User Forum    :: Powered by YaBB
  « MIDI-OX User Forum - Sysex HEX Conversion to Decimal »
Welcome, Guest. Please Login or Register.
May 15th, 2025, 8:19am


Home Home Help Help Search Search Members Members Login Login Register Register


   MIDI-OX User Forum
   MIDI-OX
   Scripting Questions
(Moderator: Jamie OConnell)
   Sysex HEX Conversion to Decimal
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Sysex HEX Conversion to Decimal  (Read 4993 times)
abhunkin
Member
**



MIDI-OX Rules!

   
WWW Email

Posts: 35
Sysex HEX Conversion to Decimal
« on: May 21st, 2007, 9:57pm »
Quote Quote Modify Modify

I need to convert the seventh byte of an incoming 8-byte sysex string to a decimal value in order to output it in a standard MIDI message. Here's the code:
 
Sub Sink_SysExInput(strSysEx)
 
    If Len(strSysEx) = 24 Then
 sysex = Split(strSysex)
 mox.OutputMidiMsg -1, 232, 0, sysex(6)
 Exit Sub
    End If
 
    mox.SendSysExString strSysEx
 
End Sub
 
The data conversion only works when the input byte (sysex(6)) < 10dec. The values will range from 0-127dec.
 
How can I convert this byte correctly?
 
TIA -
IP Logged

Art Hunkins
abhunkin@uncg.edu
http://www.arthunkins.com
JerryJorgenrud
New Member
*



MIDI-OX Rules!

   


Posts: 0
Re: Sysex HEX Conversion to Decimal
« Reply #1 on: May 22nd, 2007, 8:12am »
Quote Quote Modify Modify

Replace sysex(6) with cint("&H" & sysex(6))
 
example script - save as something.vbs
 
strSysEx = "F0 42 13 56 45 7A 7F F7 "
If Len(strSysEx) = 24 Then
sysex = Split(strSysex)
msgbox sysex(6)
msgbox cint("&H" & sysex(6))
End if
 
IP Logged
abhunkin
Member
**



MIDI-OX Rules!

   
WWW Email

Posts: 35
Re: Sysex HEX Conversion to Decimal
« Reply #2 on: May 22nd, 2007, 11:57am »
Quote Quote Modify Modify

Thanks, Jerry. That works perfectly.
 
In my case, the CInt cast seems optional, and my code runs well without it. Since I know the incoming value will be an integer between 0-127, is it safe to omit the CInt?
IP Logged

Art Hunkins
abhunkin@uncg.edu
http://www.arthunkins.com
JerryJorgenrud
New Member
*



MIDI-OX Rules!

   


Posts: 0
Re: Sysex HEX Conversion to Decimal
« Reply #3 on: May 22nd, 2007, 3:03pm »
Quote Quote Modify Modify

As you know, VBScript uses only one kind of variable, known as a variant, which can store any kind of data and thus vbscript is called a "typeless" language. But under the hood the interpreter still must cast to types by "guessing" based on context. It didn't correctly guess your intent with sysex(6) until you added the &H as a hint that you wanted that substring interpreted as a hexadecimal number. Similarly, if I don't further cast that result to an int (in my example script) then it guesses wrong again and I get a string, not a number. If the input is "7F" instead of getting 127 I get "&H7F". In the context in which you're using it (i.e. not as an input to msgbox) VBSript is apparently guessing the way you want it to and giving you a number.
 
So is it safe to leave out the additonal cast? Depends on the context ... and one's personal risk aversion.
 
I personally prefer explicit casting because bugs come from ambiguity and the more you control the less can go wrong. Or at least you can't blame someone else when they do.  Wink
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »


MIDI-OX User Forum » Powered by YaBB 1 Gold - SP 1.3.1!
YaBB © 2000-2003. All Rights Reserved.