UAL45 Posted April 20, 2004 Report Posted April 20, 2004 Anyone who can help !! I am not a whiz kid at pointers and such. I have been very successful at pulling the data numbers from the offsets. Just when I get to Strings... well it falls apart. Can somebody look at the function below and tell me what I am doing wrong ?? Each time I runs it returns "" or null. All I am trying to do is pull the ATC Tail Number from offset 313C... ------------------------------------------------------------------------------ Public Function ACID() As String Dim ReturnVal As Long Dim RTNString As String If FSUIPC_Read(&H313C, 12, StrPtr(RTNString), ReturnVal) Then If FSUIPC_Process(ReturnVal) Then ACID = RTNString End If Else ACID = "NA" End If End Function ------------------------------------------------------------------------------ Any help would be appreciated. Brian[/code]
vdkeybus Posted April 20, 2004 Report Posted April 20, 2004 I'm not familiar with VB, but here are some remarks: 1. After ACID = RTNString, there is an End If, directly followed by Else. Is this syntax correct ? 2. When you assign the RTNString to to function's return value, does VB return the pointer to the string (like in C) or the whole string object ? In the first case, you will probably corrupt the string because it is a local object (you Dim'med it inside the function), as the storage space (stack) is immediately reused when any other function is called. Perhaps try and Dim it outside the function, i.e. at the same level as a function declaration ? This problem doesn't present itself with numbers, which may explain why everything worked fine for you up to now. Again, I'm not sure. I always program in 'C'. J.
Pete Dowson Posted April 20, 2004 Report Posted April 20, 2004 ACID = "NA" I don't know VB, but here are some possible problems for you to investigate: 1. How does the compiler know to provide space for 12 characters? Your "Dim" statements don't appear to state the maximum length needed for the string. The FSUIPC read might be overwriting something important if there aren't at least 12 character's worth of space. 2. Is this "NA" the full ATC Tail Number, or just the first 2 characters? If it isn't the complete tail number, does VB use only the length of the shorter string to do the comparison? Seems odd. In most languages a string "X" will not match a string "XY" unless you deliberately restrict the length of the comparison. 3. Is your VB system using ASCII strings in the same way as Windows and FSUIPC? The string you are reading will contain single (8-bit) bytes, one per chanracter, with a zero byte at the end. If your program is compiled to use double-width characters or Unicode, you will be expecting 2-bytes (16-bits) per character. Additionally, some languages store strings with a length byte at the beginning instead of a zero terminator at the end. All these things should be described someplace in your VB references. In the last problem, you may have to resort to using an array of byte values instead of a "string" as such, especially if your VB system cannot handle standard ASCIIZ strings ("ASCIIZ" = ASCII 8-bit characters with Zero termination). You should get some help here from other VB users. Sorry if my hypothesising makes it look rather complex. I'm sure it can't be that bad (though I must say I grew to hate VB a long time ago! :wink: ). Regards, Pete
jd Posted April 20, 2004 Report Posted April 20, 2004 as soon as i get back from work, i'll post my routine to read aircraft id
UAL45 Posted April 20, 2004 Author Report Posted April 20, 2004 Thanks All for your input. vdkeybus: The syntax is good. As far as corruption of the values / pointer . . I dont know... That is what I am hoping somebody will shed some light on. Thanks for the insight and help. Pete: Yes, the compiler allows for that length and does use ASCIIZ. I am sure that I am just screwed up on how to reference the string pointer. By the way the "NA" is just a default return value if the FSUIPC read fails, nothing fancy. jd: Thank you !! I look forward to your post !! Thanks again all.. Brian
Pete Dowson Posted April 20, 2004 Report Posted April 20, 2004 By the way the "NA" is just a default return value if the FSUIPC read fails, nothing fancy. The Read is less likely to fail than the Process, because it doesn't really do anything other than add the request into a buffer in your own program. To do what you really want to do you need the Else ACID = "NA" within the If/Endif section for the Process. If VB accepts compound logic without executing both parts, you can of course combine both If's into one, with an "AND". This works okay in C/C++ because the code processes the separate condition from left to right, and will stop when the condition proves false. It may not work in VB though. None of this helps with your actual problem, though. Sorry. I'm not able to answer that. Regards, Pete
UAL45 Posted April 20, 2004 Author Report Posted April 20, 2004 Pete, Good point. I have found it that if the read fails so does the process. So, I just set the "NA" in the one istance. It would be better for me to have both. I think the jd will be able to help me later today. Either way, good chance to hear what others think and learn something. Isnt that what it is all about ?? Regards, Brian
DocNZ Posted April 21, 2004 Report Posted April 21, 2004 This is how I do it in Borland Delphi Pascal. The translation to VB should be very straigt forward. var dwResult:DWord; Aircraft:array[0..256] of char; ACTailNum:array[0..12] of char; begin if FSUIPC_Read($3d00, 256, @aircraft, dwResult) then begin if FSUIPC_Process(dwResult) then Label1.Caption := aircraft else DoCantConnect(dwResult); end; if FSUIPC_Read($313C, 12, @ACTailNum, dwResult) then begin if FSUIPC_Process(dwResult) then Label2.Caption := ACTailNum else DoCantConnect(dwResult); end; end; I hope this helps. (PS DoCantConnect is a procedure to handle errors reading from FSUIPC) Paul T.
UAL45 Posted April 21, 2004 Author Report Posted April 21, 2004 Thanks Paul !! One question, tho.. In the calls you pass the aircraft as @aircraft. In PASCAL is the @ the same as pointing to the address space for the variable named aircraft ? Where I am getting lost and confused is between the var pointers and string pointers in VB. Your calls look similar to what I am doing, however, I am still getting an empty string returned to me... Brian
DocNZ Posted April 22, 2004 Report Posted April 22, 2004 yes @ is the delphi pointer operand. I dont think Delphi makes the distinction between whether a pointer points to a string or an integer etc. In Delphi a pointer is a pointer. The distenction is made by the variable you declare. If I declared ACTailNum as an integer, then what whould be returned is a 12byte number, and not a null terminated string. In your code I noticed that you declared RTNString as a string, whereas I decalre ACTailNum as an array of 12 characters. I think I would get an error if I declared it as a string in delphi too, becaue that @ACTailNum points to is not actually a string. I just dont know, but isnt there an example of this very thing for VB in the FSUIPC SDK?
Armando Chibante Posted April 22, 2004 Report Posted April 22, 2004 Hi Brian, This is how I read a string in VB6: Dim acName() As Byte Dim CraftName As String Dim dwResult As Long Dim cnt as Long If Not FSUIPC_Read(&H3D00, 256, VarPtr(acName(1)), dwResult) Then Exit Sub ' Aircraft name If FSUIPC_Process(dwResult) Then cnt = 1 Do While acName(cnt) <> 0 CraftName = CraftName & Chr(acName(cnt)) cnt = cnt + 1 Loop End If Hope this helps Armando Chibante
UAL45 Posted April 22, 2004 Author Report Posted April 22, 2004 Armando, Thank You. So.. it is a byte by byte move. Thanks !!! Brian
UAL45 Posted April 24, 2004 Author Report Posted April 24, 2004 Works great now !! Just be sure to: Dim acName(X) As Byte Where x is the length of the string to be read or some nasty compile errors show. Thanks again everyone for your help !!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now