Solved

What is the equivalent of the strtoul routine in VB?

Posted on 2004-03-30
12
365 Views
Last Modified: 2012-06-21
I am porting a routine from C to VB and have everything done except I need a way of simulating the C strtoul routine. This routine converts a string to an unsigned long.

I've done quite a bit in VB but this is over my head.
0
Comment
Question by:mnorma12
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 10717135
LongToUnsigned(clng(yourval))
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 10717141
or

LongToUnsigned(clng(val(yourval)))
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 10717146
0
 
LVL 6

Assisted Solution

by:___XXX_X_XXX___
___XXX_X_XXX___ earned 200 total points
ID: 10717284
If strString is the string that you want to convert to long use this:

Dim strString As String
Dim lngLong As Long

strString="53224356"
lngLong=Clng(Val(strString))






Or just:
lngLong=Val(strString)
0
 
LVL 5

Expert Comment

by:g0rath
ID: 10717286
LONG in VB = -2,147,483,647 to 2,147,483,647
DOUBLE in VB = 4.94065645841247E-324 to 1.79769313486232E308 and stored as IEEE 64-bit 8 byte numbers

there isn't a "real" unsigned long int in VB, your more or less just typecasting to something larger that just so happens to hold those values. Just be warned if this is necessary for file I/O as it's 8 bytes not 4 in case that is an issue
0
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10717468
Yes, g0rath is right, but Long type in VB is only "native" type in VB that is integer and big enough to hold 2^32 values (half negative and other positive) and it is close enough to unsigned long in C.
Mathematical operation with Long variable will result in Long variable (integer).
If you use Double value type, these 64 bits can't contain all 1.79*10^308 values and mathematical operations with it can contain non-exact results, but may contain values larger than 2^31 (the upper bound for Long variables).

If you don't want to make non-integer mathematical operations with Long variable, it will suits your needs in interval -2^31 to +2^31.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 48

Expert Comment

by:Mikal613
ID: 10717521
Shkoach
0
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10717819
"Shkoach" ???
0
 

Author Comment

by:mnorma12
ID: 10723754
Sorry it's taken me so long to get back to you guys. I've been away from my computer since yesterday afternoon. I'll give a few of these a try and get back to you.

Thanks
0
 

Author Comment

by:mnorma12
ID: 10723850
The expression I am needing to duplicate is

ZoneNumber=strtoul(UTMZone, &ZoneLetter, 10)

What would this look like in Vb?
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 200 total points
ID: 10723874
ZoneNumber=LongToUnsigned(Clng(Val(UTMZone)))
0
 

Author Comment

by:mnorma12
ID: 10724057
Thanks guys that wasn't as hard as I thought it might be. When I went through and read a summary of the strtoul routine I just got more confused. Anyways great work!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now