help on data type conversion

Reply

Join Date: Jun 2005
Posts: 11
Reputation: aaron_tan is an unknown quantity at this point 
Solved Threads: 0
aaron_tan aaron_tan is offline Offline
Newbie Poster

help on data type conversion

 
0
  #1
Jun 7th, 2005
I desperately need help on data type conversions. I am working on converting a set of codes in Visual Basic to C but i'm faced with a lot of problems dealing with strings. Can anyone help me out here? Below is the code I have in Visual Basic.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Function RegGetStringValue(ByVal hKey As Long, _
  2. ByVal sValue As String, _
  3. dwDataSize As Long) As String
  4.  
  5. Dim sDataRet As String
  6. Dim dwDataRet As Long
  7. Dim success As Long
  8. Dim pos As Long
  9.  
  10. 'returns number of spaces based on dwDataSize
  11. sDataRet = Space$(dwDataSize)
  12.  
  13. 'get the size of the null terminating char
  14. dwDataRet = Len(sDataRet)
  15.  
  16. success = RegQueryValueEx(hKey, sValue, _
  17. ByVal 0&, dwDataSize, _
  18. ByVal sDataRet, dwDataRet)
  19.  
  20. If success = ERROR_SUCCESS Then
  21. If dwDataRet > 0 Then
  22.  
  23. pos = InStr(sDataRet, Chr$(0))
  24. RegGetStringValue = Left$(sDataRet, pos - 1)
  25.  
  26. End If
  27. End If
  28. End Function
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: help on data type conversion

 
0
  #2
Jun 7th, 2005
*Has A Headache Just Thinking About It*

Understand, that this will be the bloodiest, most brutal war in computer history.... as long as you are aware of this....Seeing That VB Misses A HUGE number of things that C is able to accomplish. You don't have pointers, you don't have structs or unions... user defined types... sure. Then you have to take into account that strings in VB are NOT (well they are internally, but not in any helpful form to you) array's of type char. However, here is how you can cast things in VB:

Cint(expression) casts expression to an integer. If expression is a floating-point value or a currency value, it is rounded. If it is a string that looks like a number, it is turned into that number and then rounded if necessary. If it is a Boolean value of True, it becomes a -1. False becomes 0. It must also be within the range that an integer can store.

Cbyte(expression) casts expression to a byte value provided that expression falls between 0 and 255. expression should be numeric or something that can be cast to a number.

Cdbl(expression) casts expression to a double. expression should be numeric or something that can be cast to a number.

Csng(expression) casts expression to a single. It works like Cdbl(), but must fall within the range represented by a single.

Cbool(expression) casts expression to a Boolean value. If expression is 0, the result is False. Otherwise, the result is True. expression should be numeric or something that can be cast to a number.

Ccur(expression) casts expression to a currency value. expression should be numeric or something that can be cast to a number.

Cdate(expression) casts expression to a date value. expression should be numeric or something that can be cast to a number, or a string of a commonly used date format.
DateValue(expression) or TimeValue(expression) can also be used for this.

Cstr(expression) casts expression to a string. expression can be any kind of data.


Good Luck To you...
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 11
Reputation: aaron_tan is an unknown quantity at this point 
Solved Threads: 0
aaron_tan aaron_tan is offline Offline
Newbie Poster

Re: help on data type conversion

 
0
  #3
Jun 7th, 2005
Thanks for replying...that certainly helped me in understanding the VB codes..

But what i am actually looking for is data type conversions in C :o
What i need is exactly what you posted...but in C >_<

By the way...i apologise for the duplicate post...wanted to look for help in both places
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: help on data type conversion

 
0
  #4
Jun 7th, 2005
You aren't the first to duplicate post

Ok, In C, you can CAST a Variable with this syntax:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. (type)variable

So, For Example, Let's say that you want to take the floating point number x, and use it as an integer:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. float x = 1.1;
  2. int y = 2;
  3. answer = (int)x + y;

Now, I try not to code in C much, and my syntax could be a bit off... but that should took the floating point variable x, and cast it as an integer, and add it with y. So, you can cast any type as far as I know. The types that I know of are:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. char
  2. short
  3. int
  4. long
  5. float
  6. double
  7. long double

Hope this helps.... and let me know if you need anything else. I'll also talk to an admin about WHERE this thread should go.... it seems to me it's a vb app right?
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 11
Reputation: aaron_tan is an unknown quantity at this point 
Solved Threads: 0
aaron_tan aaron_tan is offline Offline
Newbie Poster

Re: help on data type conversion

 
0
  #5
Jun 8th, 2005
Thanks for the help~!Really appreciate it~

ya that is a vb app...but i'm actually looking for help in C...because my objective is to get that chunk of code converted to C.
i'm kinda confused on where i should post the thread in so i decided to create a post in each of them.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC