|
-
Aug 23rd, 2005, 11:02 AM
#1
Thread Starter
Frenzied Member
function to determine if the variable is "-"
Hello
is there a function which would enable me to determine if the contents of a variable is say "-"
Last edited by vb_student; Sep 1st, 2005 at 11:05 AM.
-
Aug 23rd, 2005, 11:30 AM
#2
Re: function to determine if the variable is "-"
Yes, you can use Instr function to test for it and return the index position of it in the variable string.
VB Code:
Dim str As String
Dim iRet As Integer
str = "VB-Office Guru"
iRet = Instr(1, str, "-")
If iRet > 0 Then
MsgBox "Contains a '-' at position: " & iRet ' = 3
Else
MsgBox "does not contain a '-'"
End If
Last edited by RobDog888; Aug 23rd, 2005 at 12:37 PM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 23rd, 2005, 12:23 PM
#3
Frenzied Member
Re: function to determine if the variable is "-"
Minor correction ... the opening quote is required ...
str = "VB-Office Guru"
"InStr" is nice in that it automatically casts a number to a string, so you can detect negative signs (-) in numbers as well as hyphens (-) in text strings !!!
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Aug 23rd, 2005, 12:38 PM
#4
Re: function to determine if the variable is "-"
What type-o? You didn't see nut'n. 
Thanks.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 1st, 2005, 11:08 AM
#5
Thread Starter
Frenzied Member
Re: function to determine if the variable is "-"
i meant do a comparison of a single character to check if the character is '-' or not.
i guess i could do something like
VB Code:
str = '-'
if str='-' then
MsgBox "it is a -"
else
MsgBox "it is not a -"
-
Sep 1st, 2005, 02:39 PM
#6
Frenzied Member
Re: function to determine if the variable is "-"
You can certainly do that, but you need an "End If" at the end. You can still use the "Instr" for the a character match in any string if you want ... but it can't tell you if the string happens to be longer than 1 character.
Last edited by Webtest; Sep 1st, 2005 at 02:45 PM.
Reason: re-worded statement
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Sep 1st, 2005, 02:44 PM
#7
Re: function to determine if the variable is "-"
If needs be you can also scan through a string character by character to determine what it is (loop around the length using MID), or if you are needing to replace a certain character with another then the REPLACE function will help.
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Sep 2nd, 2005, 04:48 PM
#8
Thread Starter
Frenzied Member
Re: function to determine if the variable is "-"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|