473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Visual Basic 6 - Getting value before a "-"

6
I'm writing code in vb 6. I need to get the left value of a string before the "-'. What is the syntax to do this.

Example:

sTestNumber is a string and the value is "Parks-87364-2734". I want to save
"Parks" into the string value sNameOnly.

What is the code to accomplish this?

Thanks,
Nov 12 '07 #1
5 1273
jamesd0142
469 256MB
I'm writing code in vb 6. I need to get the left value of a string before the "-'. What is the syntax to do this.

Example:

sTestNumber is a string and the value is "Parks-87364-2734". I want to save
"Parks" into the string value sNameOnly.

What is the code to accomplish this?

Thanks,
sNameOnly = sTestNumber.substring(1,5)

or

i once used something like:
sNameOnly = sTestNumber.substring(1,charindex("-"))
but cant remember exactly how it worked.

on the other hand this works...
Expand|Select|Wrap|Line Numbers
  1.        Dim i As Integer
  2.         Dim a As String
  3.         Dim sNameOnly As String
  4.         Dim sTestNumber As String 
  5.         sTestNumber = "Parks-87364-2734"
  6.  
  7.         For i = 1 To Len(sTestNumber)
  8.             a = Mid(sTestNumber, i, 1)
  9.             If a <> "-" Then
  10.                 sNameOnly = sNameOnly + a
  11.             Else
  12.                 'do something
  13.                 Exit Sub
  14.             End If
  15.         Next
  16.  
Nov 12 '07 #2
debasisdas
8,127 Expert 4TB
Use combination of left and mid function. No need of loops here.
Nov 12 '07 #3
jamesd0142
469 256MB
Use combination of left and mid function. No need of loops here.
so how can i use the left and mid functions to get substring of "Parks-87364-2734" at the index of "-"???

I cant work this out myself :P
Nov 12 '07 #4
jamesd0142
469 256MB
ok this works cheers for the guidence
Expand|Select|Wrap|Line Numbers
  1. Dim sNameOnly As String
  2. Dim sTestNumber As String = "Parks-87364-2734"
  3. sNameOnly = sTestNumber.Substring(0, (sTestNumber.IndexOf("-", 0) + 1) - 1)
  4. MsgBox(sNameOnly)
  5.  
Nov 12 '07 #5
Killer42
8,435 Expert 8TB
That will not work in VB6. Try this conversion...

Expand|Select|Wrap|Line Numbers
  1. Dim sNameOnly As String
  2. Dim sTestNumber As String
  3. sTestNumber = "Parks-87364-2734"
  4. sNameOnly = Left$(sTestNumber, Instr(sTestNumber, "-") - 1)
  5. MsgBox(sNameOnly)
Or, as an alternative...
Expand|Select|Wrap|Line Numbers
  1. Dim sNameOnly As String
  2. Dim sTestNumber As String
  3. sTestNumber = "Parks-87364-2734"
  4. sNameOnly = Split(sTestNumber, "-")(0)
  5. MsgBox(sNameOnly)
Note, I just typed these here, haven't tested either.
Nov 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: John | last post by:
I have a problem, it's not with any code I have because... there is no code. When I run a blank visual basic 6 form, it opens up just fine. When I add a text box, a caption, and a button... it...
5
by: Greg | last post by:
I am developing an application where I need to secure a workstation for periods of time. I can use BlockInput to stop users from task switching or messing with the keyboard, but I would like to...
14
by: Aaron | last post by:
Is it possible to use .net framework 1.1 in vs2005? where can i find a list of new features of .net framework 2.0? thanks
4
by: Christian Blackburn | last post by:
Hi Gang, I saw this for sale online: Microsoft Visual Basic.NET Deluxe Learning Edition Version 2003. I'm wondering is the CD that's bundled with the learning edition just a digitized version of...
7
by: gerryLowry::Ability Business Computer Services {KC | last post by:
"Getting Back Your Visual Basic 6.0 Goodies" by Billy Hollis, 2003-5-14, states: "Getting a Forms Collection Visual Basic 6.0 developers are often fond of looping through the currently loaded...
27
by: code_wrong | last post by:
Visual Basic (not dot net) what is the best way to check the User has entered an integer into an InputBox? isNumeric() checks for a numeric value .. but does not notify of numbers with decimal...
1
by: praful pathak | last post by:
i i am praful pathak,porbandar i want to develop my own cross tab report in visual basic 6 i know what developed query from ms access but how to coded in visual basic in designing time and how to...
6
by: | last post by:
Hi, I'm steel trying to read and update my XML file with Visual Basic Express but i am unable to find the right way to read my xml file and update it if neccessary... Here is my problem :...
0
by: AJIT PITALE | last post by:
Hi, I am using Visual Basic 6 as front end and Visual FoxPro as a Database. I am trying to pass a parameter from VB to Visual FoxPro's Stored Procedure. I am getting an error showing "Data...
4
by: Chris Asaipillai | last post by:
Hi there My compay has a number of Visual Basic 6 applications which are front endeed onto either SQL Server or Microsoft Access databases. Now we are in process of planning to re-write these...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.