473,588 Members | 2,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is syntax to test if Object is a String?

I would like to know the syntax to check that an Object is a String.

If it was a number test I might use IsNumeric.
But there is no function: IsString (is there?)
--
Joe Fallon


Nov 20 '05 #1
12 49291
* "Joe Fallon" <jf******@nospa mtwcny.rr.com> scripsit:
I would like to know the syntax to check that an Object is a String.

If it was a number test I might use IsNumeric.
But there is no function: IsString (is there?)


\\\
Dim o As Object = 2
Dim p As Object = "Hello"
Dim q As Object = Me
MsgBox(TypeOf o Is String)
MsgBox(TypeOf p Is String)
MsgBox(TypeOf q Is String)
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Always figure it out 5 seconds after posting!! <g>

If Object.GetType Is GetType(String) Then

--
Joe Fallon


"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
I would like to know the syntax to check that an Object is a String.

If it was a number test I might use IsNumeric.
But there is no function: IsString (is there?)
--
Joe Fallon

Nov 20 '05 #3
On Wed, 22 Oct 2003 16:39:56 -0400, "Joe Fallon"
<jf******@nospa mtwcny.rr.com> wrote:
I would like to know the syntax to check that an Object is a String.

If it was a number test I might use IsNumeric.
But there is no function: IsString (is there?)


If TypeOf something Is String Then
....

Nov 20 '05 #4
If TypeOf Object Is String Then

Perfect!
Thanks!
--
Joe Fallon

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:bn******** ****@ID-208219.news.uni-berlin.de...
* "Joe Fallon" <jf******@nospa mtwcny.rr.com> scripsit:
I would like to know the syntax to check that an Object is a String.

If it was a number test I might use IsNumeric.
But there is no function: IsString (is there?)


\\\
Dim o As Object = 2
Dim p As Object = "Hello"
Dim q As Object = Me
MsgBox(TypeOf o Is String)
MsgBox(TypeOf p Is String)
MsgBox(TypeOf q Is String)
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #5
"Joe Fallon" <jf******@nospa mtwcny.rr.com> schrieb
I would like to know the syntax to check that an Object is a
String.

If it was a number test I might use IsNumeric.
But there is no function: IsString (is there?)


You didn't supply details, so I guess the answer is

If typeof o is string then

end if
--
Armin

Nov 20 '05 #6
Joe,
I would recommend what Herfried showed:

If Typeof obj Is String Then

The difference being is that TypeOf will succeed for derived types, where as
GetType matches the type exactly. For String not much of a difference, for
other types that you derive from, such as Control it can be a world of
difference.

Dim c As Control
c = New TextBox

If TypeOf c Is Control Then
' True : TextBox inherits from Control
End If

If c.GetType() Is GetType(Control ) Then
Else
' False : c is actually a TextBox
End If

Hope this helps
Jay

"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:ek******** *****@TK2MSFTNG P10.phx.gbl...
Always figure it out 5 seconds after posting!! <g>

If Object.GetType Is GetType(String) Then

--
Joe Fallon


"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
I would like to know the syntax to check that an Object is a String.

If it was a number test I might use IsNumeric.
But there is no function: IsString (is there?)
--
Joe Fallon


Nov 20 '05 #7
Jay,
Thanks.
I did switch my code to:
If Typeof obj Is String Then

because it seemed "more elegant".

But now I know it is also "safer".

Good advice. Appreciate it!
--
Joe Fallon
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Joe,
I would recommend what Herfried showed:

If Typeof obj Is String Then

The difference being is that TypeOf will succeed for derived types, where as GetType matches the type exactly. For String not much of a difference, for
other types that you derive from, such as Control it can be a world of
difference.

Dim c As Control
c = New TextBox

If TypeOf c Is Control Then
' True : TextBox inherits from Control
End If

If c.GetType() Is GetType(Control ) Then
Else
' False : c is actually a TextBox
End If

Hope this helps
Jay

"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:ek******** *****@TK2MSFTNG P10.phx.gbl...
Always figure it out 5 seconds after posting!! <g>

If Object.GetType Is GetType(String) Then

--
Joe Fallon


"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
I would like to know the syntax to check that an Object is a String.

If it was a number test I might use IsNumeric.
But there is no function: IsString (is there?)
--
Joe Fallon



Nov 20 '05 #8

"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
I would like to know the syntax to check that an Object is a String.

If it was a number test I might use IsNumeric.
But there is no function: IsString (is there?)
--
Joe Fallon

In Object-oriented programming, type-checking is considered a "poor
practice". Depending upon what you are trying to accomplish, consider using
polymorphism to accomplish your task. Then, instead of "testing" to see
what object you are using, the object itself will know the correct response
for the message you are sending to it.

Gary O.
Nov 20 '05 #9
I have an argument that takes an Object.
But in the special case when the Object is a String I need to do something
extra.

So this is perfect for my needs:
If TypeOf something Is String Then
--
Joe Fallon

"Gary Owsiany" <ga*****@swbell .net> wrote in message
news:Qp******** ********@newssv r24.news.prodig y.com...

"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
I would like to know the syntax to check that an Object is a String.

If it was a number test I might use IsNumeric.
But there is no function: IsString (is there?)
--
Joe Fallon

In Object-oriented programming, type-checking is considered a "poor
practice". Depending upon what you are trying to accomplish, consider

using polymorphism to accomplish your task. Then, instead of "testing" to see
what object you are using, the object itself will know the correct response for the message you are sending to it.

Gary O.

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
27819
by: Brenda | last post by:
We are currently switching to DB2/AIX. I am modifying my sqrs to work on this new platform. (We are currently on Oracle). I am having a problem with an sqr that has a reference to a variable for a date field. I have copied that section of the select statement below. You can see the old code that I used for Oracle--that works great--which I have commented out and the new line I added just below. When this sqr runs, it throws the...
1
1753
by: Jean Stax | last post by:
Hi ! A couple of pretty basic questions: Value types: As far as I understand, when I create value type without "new" syntax the object is considered as unutilized. Consequently, I have to initialize its member variables manually; otherwise I would get an exception while accessing them.
1
1563
by: Jean Stax | last post by:
Hi ! A couple of pretty basic questions: Value types: As far as I understand, when I create value type without "new" syntax the object is considered as unutilized. Consequently, I have to initialize its member variables manually; otherwise I would get an exception while accessing them.
6
7190
by: SevDer | last post by:
Is there a way to test guid string? I want to do it without try catch block to save on performance. Thanks in advance. -- SevDer
3
3132
by: MMiGG | last post by:
Hi Our project need parse JAVA serialized object string in C, has any library? Thanx
13
20731
by: titan nyquist | last post by:
How do you test a string to see if it contains special characters? I want to ensure that any names typed into my form has only letters (and maybe allow a dash and an apostrophe). I can loop RealName.Contains("..."), but there must be a more elegant solution.
0
1369
by: Java25 | last post by:
I am trying to insert a date to my access database and i get the error below. please help: Syntax error in string in query expression ''Fri Jun 08 10:49:00 CAT 2007)'. I only want in the format dd/mm/yyyy
4
11681
by: srinathvs | last post by:
Hi, I have an access db that I am trying to query from a vb6 program. I've the following code: Dim sSQLQuery As String sSQLQuery = "SELECT * FROM TblData WHERE ID = " & Chr(39) & ID & Chr(39) ID here is equal to 1234567890 MsgBox sSQLQuery the msgbox says: SELECT * FROM TblData WHERE ID = '1234567890 Note that the quotation is missing at the end Set rs = db.OpenRecordset(sSQLQuery, dbOpenDynaset)
5
8823
by: rolltide | last post by:
I've seen many similar threads, but despite repeated efforts I cannot figure out my problem. I am running Access 2003, VB 6.5, Office XP Pro. Code excerpt is below (you can see where I've tried debugging myself). My problem is in the DLookup command. UserName = Me.cboUserName.Value Debug.Print "User Name is "; UserName strPassword = DLookup("Password", "Employees", "EmpName ='" & UserName) Debug.Print "Password is ";...
2
5079
by: David Knock | last post by:
I am a noob and was wondering how to fix this problem Error: syntax error before string constant I am trying to write the simple hello world code here it is #include "stdlib.h" int main () "using namespace std;" { cout << "hello world!" ; cin.get ();
0
7862
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8223
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5398
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2372
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1196
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.