mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2004
Posts: 423
C
Fjord artisan
OP Offline
Fjord artisan
C
Joined: Aug 2004
Posts: 423
hello again,

i'm currently trying to learn about hash tables, i'm confident i understand the basics (somewhat, anyways) and i'm having some problems with combining a hash table with a dialog.. with the help of one of the hash tutorials and a couple of posts i found here grin, i have managed to get this far :

Code:
on *:start:{
  .hmake amacros 100
  if ($isfile(/amshdir(amsacros.hsh))) {
    .hload amacros $amshdir(amsacros.hsh)
  }
  else {
    /amsacros.start
    .hsave -o amacros dat\hsh\amsacros.hsh
  }
}

on *:EXIT: {
  .hsave -o amacros dat\hsh\amsacros.hsh
  .hfree amacros
}

on *:input: {
  if ( $left($1,1) != / ) {
    var %w = 1              
    var %text               
    var %acro = [<acronym>] 
    while ($gettok($1-, %w, 32) != $null) { 
      var %word = $v1
      if ($hget(acronym, %word) != $null) var %text = %text $replace(%acro, <acronym>, $v1)
      else var %text = %text %word
      /inc %w
    }
    //echo -a %text
    /halt
  }
}
alias amshdir return (",$mircdirdat\hsh\,$1,")

alias amsacros.start {
  .hadd amacros afk Away From Keyboard
  .hadd amacros brb Be Right Back
  .hadd amacros gtg Got To Go
  .hadd amacros lol Laughing Out Loud
  .hadd amacros ttyl Talk To You Later
}

dialog acro_test {
  title "$amlogo ACRONYMS"
  size -1 -1 314 200
  option dbu
  list 1, 16 64 82 107, size vsbar
  edit "", 3, 16 46 82 10
  edit "", 4, 147 46 150 10
  list 2, 147 64 149 107, size vsbar
  button "Add Acro", 5, 91 25 37 9
  button "Del Acro", 6, 133 25 37 9
  text "Input TexT", 7, 41 35 27 8
  text "Output TexT", 8, 208 35 32 8
  text "A", 9, 120 56 4 8 
  text "C", 10, 120 69 5 7 
  text "R", 11, 120 81 5 7
  text "O", 12, 120 93 5 7
  text "N", 13, 120 105 4 7
  text "Y", 14, 120 117 4 8
  text "M", 15, 120 129 5 8
  text "S", 16, 120 141 4 8
  button "Okay", 17, 104 186 37 12, ok
}

on *:dialog:acro_test:*:*: {
  if ($devent == init) {
    if !$hget(amacros) { hamke amacros 100 | hload amacros $amshdir(amsacros.hsh) }
    var %x = 1
    while $hget(amacros,%x).item {
      did -a $dname 1 $v1
      inc %x
    }
    var %y = 1
    while $hget(amacros,%y).data {
      did -a $dname 2 $v1
      inc %y
    }
  }
}
  


now, if you test the code you'll see that it loads the hash data in the correct spots just fine. but now i'm unsure how to add/del into and from the dialog an hash at the same time. plus i'm sure this existing code might need fixing as is.... and any other tips will be appreciated greatly...

so if anyone can help/advise i'm asking to feel free and do so.......

thanks in advance confused

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Code:
on *:dialog:acro_test:*:*: {  
  if ($devent == init) {    
    if !$hget(amacros) { hamke amacros 100 | hload amacros $amshdir(amsacros.hsh) }    
    var %x = 1    
    while $hget(amacros,%x).item { 
      did -a $dname 1 $v1 
      inc %x  
    }  
    var %y = 1 
    while $hget(amacros,%y).data {
      did -a $dname 2 $v1  
      inc %y 
    }
  }
  if ($devent == sclick) {
    if ($did == 5) {
      if ($hget(amacros)) {
        hadd amacros $did($dname,3).text $did(acro_test,4).text
        did -a acro_test 1 $did($dname,3).text
        did -a acro_test 2 $did($dname,4).text 
      }
    }
    if ($did == 6) {
      if ($did(acro_test,1).sel) {
        if ($hget(amacros)) {
          set %line $did(acro_test,1).sel
          hdel amacros $did(acro_test,1).seltext
          did -d acro_test 1 %line
          did -d acro_test 2 %line
        }
      }
    }
  }
}

Last edited by SladeKraven; 18/01/05 07:21 PM.
Joined: Aug 2004
Posts: 423
C
Fjord artisan
OP Offline
Fjord artisan
C
Joined: Aug 2004
Posts: 423
duhhhhhhhh, i feel dumb now for not realizing it was that easy......

thanks slade! cool

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
You're welcome. wink

Joined: Aug 2004
Posts: 423
C
Fjord artisan
OP Offline
Fjord artisan
C
Joined: Aug 2004
Posts: 423
now, i have another question shocked .....

how would i be able to aff something that checks for duplicate entries and prevent'em ????

Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Hash tables won't have duplicate item names, so just /hsave -o the table smile

Joined: Aug 2004
Posts: 423
C
Fjord artisan
OP Offline
Fjord artisan
C
Joined: Aug 2004
Posts: 423
lol ok,

thanks Iori
:tongue:


Link Copied to Clipboard