| | |
help on data type conversion
![]() |
•
•
Join Date: Jun 2005
Posts: 11
Reputation:
Solved Threads: 0
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)
Private Function RegGetStringValue(ByVal hKey As Long, _ ByVal sValue As String, _ dwDataSize As Long) As String Dim sDataRet As String Dim dwDataRet As Long Dim success As Long Dim pos As Long 'returns number of spaces based on dwDataSize sDataRet = Space$(dwDataSize) 'get the size of the null terminating char dwDataRet = Len(sDataRet) success = RegQueryValueEx(hKey, sValue, _ ByVal 0&, dwDataSize, _ ByVal sDataRet, dwDataRet) If success = ERROR_SUCCESS Then If dwDataRet > 0 Then pos = InStr(sDataRet, Chr$(0)) RegGetStringValue = Left$(sDataRet, pos - 1) End If End If End Function
*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...
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...
You aren't the first to duplicate post 
Ok, In C, you can CAST a Variable with this syntax:
So, For Example, Let's say that you want to take the floating point number x, and use it as an integer:
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:
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?

Ok, In C, you can CAST a Variable with this syntax:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
(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)
float x = 1.1; int y = 2; 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)
char short int long float double 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?
![]() |
Similar Threads
- Working with SQL server's Image data type (ASP.NET)
- Data loss in Type Conversion. (C++)
- Problems with changing values returned by RegQueryValueEx (C)
- Help With Data-type Declaration Symbols (Pascal and Delphi)
- Working with SQL's Text data type (ASP.NET)
- Text data type troubles in T-SQL (Database Design)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Password Generator
- Next Thread: Winsock and looping issues unsure how to resolve
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






