March 28, 2024, 10:24:50 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


LEN issue

Started by ckoehn, March 16, 2023, 07:13:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ckoehn

March 16, 2023, 07:13:23 AM Last Edit: March 16, 2023, 07:23:02 AM by ckoehn
I know and feel like I'm getting old, so maybe I'm missing something here.  I'm only going to post part of my code to show what I'm looking at.

Both Msg and sMsg are defined as STRING type.
STRING Msg is global and STRING sMsg is under my message handler.

case w1_Super
 if @NOTIFYCODE = 0
     ID = Val(GetControlText(w1, w1_ID))
     if ID <= 0
         Messagebox w1,"Please select an ID.","9300 Utility"
     elseif cport<=0
         Messagebox w1, "Please select a commport.", "9300 Utility"
     else
         Msg = "M" + Dec2Hex(ID,2) + "0111" + (Dec2Hex(ID+18,4))
         sMsg = Msg '<---- To need this makes no sense. LEN(Msg) was 28, which is wrong.
                    'LEN(sMsg) is 11 which is right
         IWSendPort(cport,sMsg,len(sMsg))
         AppendEdit(w1,w1_EDIT1,"Sending: "+sMsg,TRUE)
         rmsg = ""
     endif
I even tried to force a CHR$(0) at the end and it made no difference.

IWSendPort sent out 28 characters instead of 11 with just Msg.

This is my Hex2Dec and Dec2Hex functions.
SUB Hex2Dec(STRING txt),uINT
 INT i,pow
 UINT res

 res=0
 FOR i=1 to LEN(txt)
 pow=16^(LEN(txt)-i)
 res+=(INSTR("0123456789ABCDEF",MID$(txt,i,1),1)-1)*pow
 NEXT i
 RETURN res
ENDSUB

Sub Dec2Hex(int num, int decplaces), string
 return RIGHT$("0000000000"+HEX$(num),decplaces)
endsub


Later,
Clint

basicgames

Have you tried printing the string to the debug (or a messagebox) before converting it with LEN() just to see the actual contents? That's what I always do when things make no sense.

ckoehn

I did.  Printing it to a messagebox didn't show anything.  I also sent it to a text box in my program and it didn't show anything.  I was using a program called "Comm Tunnel" to transfer data over the internet and that is where it showed up.  That is why I started print "LEN(Msg)" to messageboxes, and realized the length was wrong.  Copying it to another string should also have made a duplicate (which I'm glad it didn't). Just another IWBasic idiosyncrasy I guess.

Later,
Clint