Hash Table Data Merger Dialog

By Scakk on Sep 20, 2008

This dialog allows you to merge the data of two items in the same hash table together. Once you merge the two items into one it will delete the second item.

Example:
First Item: Pins Steve 25
Second Item: Pins Steve|AFK 32

Once Merged:
Pins Steve 57
Pins Steve|AFK <-- gets deleted.

It will work with numbers or text. If the data is 0 or $null you can not merge them.

Image

menu channel,status {
  Hash Table Data Merger: dialog $iif($dialog(hashmerge), -va, -m) hashmerge hashmerge 
}
dialog hashmerge {
  title "Hash Table Data Merger"
  size -1 -1 255 290
  text "Tables", 1, 5 4 120 20, center
  list 2, 5 25 120 155, sort
  text "Items", 3, 130 4 120 20, center
  list 4, 130 25 120 150, sort check
  text "Hash Table", 5, 10 205 75 20, center
  edit "", 6, 100 202 150 20, center autohs
  text "Item 1 Data", 7, 18 235 75 20 center
  edit "", 8, 100 232 150 20, center autohs
  text "Item 2 Data", 9, 18 265 75 20 center
  edit "", 10, 100 263 150 20, center autohs
  button "Merge", 11, 100 175 50 25
}
on *:dialog:hashmerge:*:*: {
  if ($devent == close) { unset %did1 %did2 }
  if ($devent == init) { 
    did -b $dname 6,8,10,11
    var %x 1
    while ($hget(%x)) {
      did -a $dname 2 $hget(%x)
      inc %x
    }
    did -ra $dname 1 $iif($did(hashmerge,2).lines > 1,Tables,Table) $+($chr(40),$did(hashmerge,2).lines,$chr(41)) 
  }
  if ($devent == sclick) { 
    if ($did == 2) {
      did -r $dname 4,8,10
      did -e $dname 6
      did -b $dname 8,10
      var %x 1
      while ($hget($did(hashmerge,2).seltext,%x).item) {        
        did -a $dname 4 $hget($did(hashmerge,2).seltext,%x).item 
        inc %x
      }
      did -ra $dname 3 $iif($did(hashmerge,4).lines > 1,Items,Item) $+($chr(40),$did(hashmerge,4).lines,$chr(41))
      did -ra $dname 6 $did(hashmerge,2).seltext
    }
    if ($did == 4) { 
      if ($hget($did(hashmerge,2).seltext,$did(hashmerge,4).seltext)) {
        did -e $dname 11
        if ($did(hashmerge,4,0).csel <= 2) {
          if ($did(hashmerge,4,$did(hashmerge,4).sel).cstate == 1) {
            if ($did(hashmerge,8).enabled) { 
              did -ae $dname 10 $hget($did(hashmerge,2).seltext,$did(hashmerge,4).seltext)
              set %did2 $did(hashmerge,4).seltext
            }
            if (!$did(hashmerge,8).enabled) { 
              did -ae $dname 8 $hget($did(hashmerge,2).seltext,$did(hashmerge,4).seltext)
              set %did1 $did(hashmerge,4).seltext
            }
          }
          if ($did(hashmerge,4,$did(hashmerge,4).sel).cstate == 0) {
            if (%did1 == $did(hashmerge,4).seltext) { did -rb $dname 8 | unset %did1 }
            if (%did2 == $did(hashmerge,4).seltext) { did -rb $dname 10 | unset %did2 }
          }
        }
        if ($did(hashmerge,4,0).csel > 2) { 
          did -b $dname 6,8,10,11
          did -r $dname 3,4,6,8,10
          did -uk $dname 2
          did -a $dname 3 Items
          did -f $dname 1
          unset %did1 %did2
        }
        if ($did(hashmerge,4,0).csel = 0) { 
          did -uk $dname 4 
          did -b $dname 11          
          did -f $dname 1 
          unset %did1 %did2 
        }
      }
    }
    if ($did == 11) { 
      if (!%did1 || !%did2) { noop $input($+($str($chr(32),6),Please choose more Items.),o,Error!) }
      if (%did1 && %did2) { 
        var %did3 $hget($did(2).seltext,$(%did1,2)), %did4 $hget($did(2).seltext,$(%did2,2))
        if ($input(Are you sure you wish to add both Items $crlf $crlf $& 
          1. $did(2).seltext %did1 $hget($did(2).seltext,%did1) $crlf  $&
          2. $did(2).seltext %did2 $hget($did(2).seltext,%did2) $crlf $crlf $&
          to %did1 and delete Item %did2 $+ ?,y,Merging....?)) { 
          hadd $did(2).seltext %did1 $2 $iif(%did3 isnum && %did4 isnum, $calc(%did3 + %did4), $($(%did3 %did4),2))
          hdel $did(2).seltext %did2
          did -b $dname 6,8,10,11
          did -r $dname 3,4,6,8,10
          did -uk $dname 2
          did -a $dname 3 Items
          did -f $dname 1
          unset %did1 %did2
        }
        else {  
          did -b $dname 6,8,10,11
          did -r $dname 3,4,6,8,10
          did -uk $dname 2
          did -a $dname 3 Items
          did -f $dname 1
          unset %did1 %did2
        }
      }
    }
  }
}

Comments

Sign in to comment.
PuNkTuReD   -  Sep 20, 2008

nice , this could come in very handy
very useful

 Respond  
EL   -  Sep 20, 2008

Looks good Scakk mite have to put it to some use;p."Rate it or Hate it?"...7/10".`-.-´

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.