To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management
Building Composable Apps in .NET 4 with the Managed Extensibility Framework
CLR Inside Out: Formatting and Parsing Time Intervals in the .NET Framework 4



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old May 2nd, 2006, 09:53 AM   #1
RayComp
Member
 
Join Date: Jul 05
Posts: 36
RayComp is an unknown quantity at this point (<10)
Help wit format problem please

I'm totally at a loss with this code:

I need to store 25KG N (the N after the space to indicate Nett weight) or
I need to store 25KG G (the G after the space to indicate Gross weight)

However a calculation should be made in dbgrid1 so I am trying to strip off the alpha characters leaving only 1 to 9 (ascii 48 to 57)
and write that to DBGrid1.Columns("Max")

'Leave 0 to 9
Dim strMax As String
Dim strNet As String
Dim lngIndex As Long
Dim netIndex As Long
strMax = DBGrid1.Columns("Mass").Text
For lngIndex = Len(strMax) To 1 Step -1
If (Asc(Mid$(strMax, lngIndex, 1)) >= 48 And Asc(Mid$(strMax, lngIndex, 1)) <= 57) Then
' it's OK
Else
strMax = Replace(strMax, Mid$(strMax, lngIndex, 1), "")
End If
Next
DBGrid1.Columns("Max").Text = strMax


THIS works fine if the data in DBGrid1.Columns("Mass").Text is 25KG or 25kg or 25Kg (Upper or lower case)

Now THE PROBLEM AS soon as a space is in the string

I need to store 25KG N (the N after the space to indicate Nett weight) or
I need to store 25KG G (the G after the space to indicate Gross weight)

if I run the code
25KG N returns correctly as 25 (all with anything accept the second G is OK)

But
25KG G returns error Invalid procedure call or argument

what is funny is that sometimes it returns OK and other combinations not

25kg G or 25KG g or 25kg G returns correctly as 25

AND

25KG G or 25kG G or 25kg g or 25 Kg G returns error Invalid procedure call or argument
(Must be the second G?)
RayComp is offline   Reply With Quote
Old May 2nd, 2006, 10:02 AM   #2
Andrew G
Frenzied Member
 
Andrew G's Avatar
 
Join Date: Nov 05
Location: Sydney
Posts: 1,574
Andrew G is a jewel in the rough (200+)Andrew G is a jewel in the rough (200+)Andrew G is a jewel in the rough (200+)
Re: Help wit format problem please

VB Code:
  1. MsgBox Val("25kg N")
__________________
VB Code
Marquee ProgressBar - 3D Pie Chart
Andrew G is offline   Reply With Quote
Old May 2nd, 2006, 10:03 AM   #3
Hack
Super Moderator
 
Hack's Avatar
 
Join Date: Aug 01
Location: Sterling Heights, Michigan
Posts: 52,296
Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)
Re: Help wit format problem please

You really don't need to "strip" anything. Example:
VB Code:
  1. Dim sTest As String
  2. Dim iNumber As Integer
  3. sTest = "25KG N"
  4. iNumber = Val(sTest) 'iNumber now equals 25
  5.  
So in sTest you still have your original string which can be stored. In iNumber you have the number upon which you can do you calculations.
__________________
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum.

Creating A Wizard In VB.NET
Modifications Required For VB6 Apps To Work On Vista
Paging A Recordset
What is wrong with using On Error Resume Next
IT professionals freelancer site. Register today to find coders, or offer your services for available freelance projects!
Microsoft MVP 2005/2006/2007/2008/2009
Hack is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 02:29 AM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.