Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Why Use VbNullString


Hello, I'm new to this forum so I've been spending some time browsing it and I've noticed that some times you guys use vbNullSting why is that? Is vbNullString the same thing as an empty string? If it is why not just use an empty string instead of typing the rather long word "vbNullString"?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
VbNullString!
In a Web Browser project, I have used "" (double quotes without any space between them) in many of the If....Else conditions & also in Replace functions.

What I would like to clarify is if I change all the "" with vbNullString, will the project behave in exactly the same manner as it was before replacing vbNullString with "" or can that lead to new problems in the project?

VbNullString ?
If there is a simply way to do the same as following ?

"clientcode" sometimes is empty so it will become error if I am not doing the test, but it double the number of lines in my application !


VB Code:
if clientcode <> vbNullString then     strClientcode = clientcodeelse     strClientcode = vbNullStringend if

VbNullString
The VB Help states that "vbNullString" is not the same as the zero-length string (""). However, if I do the following

Code:
Dim s As String
s = vbNullString
If s = "" Then
MsgBox "the same"
Else
MsgBox "not the same"
End If


I get "the same". What gives?

Abt VbNullString
What is the Difference between the Following Statements :

txtName = ""

txtName = VbNullString

Which is the Better way to Follow & Why ?

Me.Picture = VbNullString
Is there any way I can get rid of the picture for my form at runtime? I tried

Me.Picture = vbNullString

but you probably knew that wasn't going to work. Any other options other than creating a blank image and loading that?

Vbnullstring Loops
I've run into a problem I can't reason out. I've got a sub that
reads a text file of 3001 'items' and puts whatever it finds between
the blank lines (each item) into a single cell in a workbook.

This works fine until I get to item 131 (see bottom for data example)
which has a blank line in it's text. I've found multiple other items
with the same blank line in the text so now my sub errors on the
first Do Loop.

I realized that the only real constant is the item numbers at the
top of each item so I added a second loop that looks for the item
number first which I set to "item$" but I can't figure out how to
have the second Do Loop read until it gets to the next item
number instead of the vbNullString. I've tried "Do Until buffer$ = item$ + 1"
and many variations of that theme but I can't get the logic right.

Can anyone point me in the right direction or am I not making
any sense?



Code:
Public Sub TextData()

Dim buffer$, item$, a$
On Error GoTo Hell

Open txtfilename$ For Input As #1
Do While Not EOF(1)
Line Input #1, buffer$
item$ = buffer$
Do Until buffer$ = vbNullString
Line Input #1, buffer$
a$ = a$ + buffer$ & vbLf
Loop
General.xlItem.Range("K" & item$ + 1) = a$
a$ = vbNullString
Loop
General.xlItem.Range("K2:K5001").WrapText = False
Close #1


Hell:
General.xlItem.Range("K" & item$ + 1) = a$
Close #1
MsgBox (Err.Number & ": " & Err.Description)
General.xlItem.Range("K2:K5001").WrapText = False
End Sub
----Data Example--------------------------------------------------

130
Were Axe Runepower gained on day 1 of January in the year of 1990
You inspect the item and discover that its essence is described in
its name.
This weapon is an Axe type weapon
It has a base AF bonus of 25% and a missile AF bonus of 0%
The charage bonus of this weapon is 0% and the rout bonus is 0%
The weapon may not be used with a shield, and it can be used while mounted.
The wielder must have a strength of 6 and a dexterity of 12 to use this weapon
The weight of this weapon is 1.2
This weapon is magical by nature...
The terrain modifiers (overall) for this weapon are as follows:
Grassland : 25 Forest : 15 Hvy Forest : 15 Forest Hills: 15
Forest Mtns : 15 Barren Hills: 0 Barren Mtns : 0 Moors : 0
Swamp : 0 Desert :-15 Sea/Ocean : 0 Defend Walls: 0
Attack Walls: 0 In City : 0 Air : 0 Confined : 0
This weapon is magically enhanced when used by a specific character or soldier.
This weapon grants a 100% AF bonus when the user meets these conditions:
The user must have a supernatural status of Werewolf.
Restrictions apply to 'IN USE' and to 'ACTIVATION'!
This weapon gives a DAMage level of 2 to it's user
This weapon grants a 50% bonus when the target meets these restrictions:
The target character must worship Hahsandra ID# 5.
The enemy must be Elf.
This weapon gives a bonus of 50 when fighting against mounted enemies
This weapon has no special attack value.
When in winternight, this weapon's AF will be modified by 25%
The following bonus will apply only if the restrictions for use are met.
Holy Mana available to Priests : 2 Holy mana recovery bonus: 0
Mana available to Arcane Arts : 2 Magic recovery bonus : 0
This weapon increases your magical attack resistance by 1 points.
Cost of Producing this Item is...
1 units of Lumber
1 units of Iron
1 units of By-product
1 unit of Mithril
This will produce 2 Were Axe

131
Shield (S) Runepower gained on day 1 of January in the year of 1990
You inspect the item and discover that its essence is described in
its name.
It has a base DF add of 2 for small sized races.
The Special Attack Resistance of this shield is 0
The charge bonus of this shield is -10 and the rout modifier is -10%.
The shield sighting value is 0.1
The weight of this shield is 1.8

The terrain modifiers (overall) for this shield are as follows:
Grassland : 0 Forest :-10 Hvy Forest :-15 Forest Hills:-10
Forest Mtns :-15 Barren Hills: 0 Barren Mtns :-5 Moors :0
Swamp : 0 Desert : 0 Sea/Ocean : 0 Defend Walls: 0
Attack Walls: 0 In City : 0 Air : 0 Confined : 0

This shield is not magically enhanced when used by a specific character or soldier.
This shield grants a 0 DF bonus, a 0 Special Attack Resistance bonus, a 0 Magical
Resistance bonus and an invulnerability rating of 0 when the user meets these conditions:
NO Restrictions on use
This shield is not a bane (no bonuses against specific target).
This shield has no special attack value.
When in winternight, the DF will be modified by 0.
The following bonus will apply only if the restrictions for use are met.
Holy Mana available to Priests : 0 Holy mana recovery bonus: 0
Mana available to Arcane Arts : 0 Magic recovery bonus : 0
This sheild increases your Magical Attack Resistance by 0 points.
Cost of Producing this Item is...
1 units of Iron
0.5 units of By-product
0.5 units of Soft Materials
This will produce 5 Shield (S)

Can A Picture = VbNullString?
Hi

I had pasted a picture box at my VB form. I am doing a project on e-passport and I had created a database. So, I had provided a photo path for each e-passport holder. I want my program to run in the way that when the passport ID is entered, the system will display all the information of the user. How the VB code can be write that I can loop it, and display the correct photo path when the passport ID is entered?



VB Code:
strSQL = "SELECT PhotoPath FROM Customer WHERE PassportID LIKE '%"    strSQL = strSQL & txtPassportID_Search.Text & "%'"        adoRS6.Source = strSQL    adoRS6.CursorType = adOpenForwardOnly    adoRS6.ActiveConnection = adoConn    adoRS6.Open    Debug.Print strSQL    Do While Not adoRS6.EOF        PicPhoto.Picture = adoRS6.Fields("PhotoPath").Value        adoRS6.MoveNext    Loop    adoRS6.Close    Set adoRS6 = Nothing


There will be an error at "PicPhoto.Picture = adoRS6.Fields("PhotoPath").Value". Do u have any suggestions to solve it? Thank you.

Vbnullstring Not Working
Im wondering why im getting this "Invalid procedure call or argument" error.
i have the codes below under keypress event.

if i used this code: it seems that the vbnullstring is not working if i leave the textbox blank and click enter key.

VB Code:
If KeyAscii = vbKeyBack Then 'backspace    Exit SubElseIf KeyAscii = 13 Then 'or vbkeyreturn    If txtBookAccNum.Text = vbNullString Then 'do stuff here        MsgBox "Enter Book's Accession Number.", vbInformation, , "NDDC-IBED Lagao Library System"        txtBookAccNum.SetFocus    Else        txtBookCallNum.SetFocus    End IfElseIf KeyAscii < 48 Or KeyAscii > 57 Then    MsgBox "Enter numeric value only.", vbInformation, "NDDC-IBED Lagao Library System"    KeyAscii = 0End If


I use this code in other part of my program and it is working fine.

VB Code:
Select Case KeyAscii                    'cursor will jump to next column    Case 13:                            ' Enter Key        If TxtAuthorLName.Text = vbNullString Then            MsgBox "Enter Author's Last Name.", vbInformation, "NDDC-IBED Lagao Library System"            TxtAuthorLName.SetFocus        Else            TxtAuthorFName.SetFocus        End IfEnd Select


Any idea why im getting such error?

Array And Vbnullstring
I have an array storing a user defined type. The type is:

VB Code:
Private Type ValueField        field As String              Value As StringEnd Type

Then I store data in the array:

VB Code:
array(index).field = "boo"array(index).value = "hello"

This works fine, but when I try to set the values to vbnullstring, sometimes the values are not replaced.

VB Code:
array(index).field = vbnullstringarray(index).value = vbnullstring

When I print out the values in the array the field may still contain "boo" instead of being NULL.

I have tried: NULL, vbNull, Empty, vbEmpty, "" but none of them ever seem to do the trick.

Will this work? Is there another way I need to do it?

Functions &amp; Type &amp; Vbnullstring
what are functions like public function fdsfsdfj() as string
and what are types? private type blalabllala

and what means vbnullstring

sorry i posted 3 questions in 1h

Replace(strstring, Chr$(34), VbNullString)
The following vba code is not saving the changes to the text file..what am I doing wrong?:

Sub changetext()
txt = "c:10318436228a.txt"
Open txt For Input As #1
strstring = Input(LOF(1), 1)
Close #1
strstring = Replace(strstring, Chr$(34), vbNullString)
End Sub

Thanks,
Aaron

Correct Assignment Of Vbnullstring
Hi,

i have spent the last few days struggling with the assignment of vbnullstring
first a little background i have a database field 'username' which alternates from a username of the loged in user to a null value (when a use logs in it checks if this field matches his/her username or isnull)

now the code that causes me an error which i would like some help to correct

Code:
dim nullname as string
nullname = vbNullString

strSQL = "UPDATE Customer SET "
strSQL = strSQL & " usergroup = '" & Replace$(newgroupid, "'", "''") & "'"
strSQL = strSQL & ", username = "
strSQL = strSQL & nullname
strSQL = strSQL & ", svalue = '" & Replace$(oldgroupid, "'", "''") & "'"
strSQL = strSQL & " WHERE custid = " & lngIDField

DBCmd.CommandText = strSQL
DBCmd.Execute

the above code causes this error - 'syntax error in UPDATE statment'

if i change

Code:
nullname = "test"

and

Code:
strSQL = strSQL & " username = '" & Replace$(nullname, "'", "''") & "'"


it works ok but i need username to be a null value any help i get on this would be great

obviously i have omitted loads of things like the connection to the database and setting up all the other variables but these all work ok.

Definition Of VbNullString And VbNullChar
How are these constants different...in what way do I use these.

I appreciate your input.

Mike

Using VbNullString To Clear A Property
Although it works, I'm not sure if I'm doing this the right way.

I'm putting tooltips on each control on a form. The tooltips are in a resource file and I have an option to toggle them on/off.

To "switch them off" as it were, I'm setting all tooltips to vbNullString. I'm wondering whether there is another "proper" way to do this or not. I'm wondering whether they should, or could be cleared from memory instead.

Thanks for any ideas.



Edited by - royalbox on 12/9/2004 6:05:56 AM

Windows VbNullString To Combmo Box Help Please
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
Declare Function GetLastError Lib "kernel32" () As Long

Public Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000

Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long

Public Const TH32CS_SNAPPROCESS As Long = 2&

Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szexeFile As String * 260
End Type
--------------------
Is on a mdlDeclares
------------------------------
Private Sub RefreshProcessList()
'Reads Process List and Fills combobox (cboProcess)

Dim myProcess As PROCESSENTRY32
Dim mySnapshot As Long

'first clear our combobox
cboProcess.Clear

myProcess.dwSize = Len(myProcess)

'create snapshot
mySnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)

'get first process
ProcessFirst mySnapshot, myProcess
cboProcess.AddItem myProcess.szexeFile ' set exe name
PIDs(cboProcess.ListCount - 1) = myProcess.th32ProcessID ' set PID

'while there are more processes
While ProcessNext(mySnapshot, myProcess)
cboProcess.AddItem myProcess.szexeFile ' set exe name
PIDs(cboProcess.ListCount - 1) = myProcess.th32ProcessID ' ' store PID
Wend

End Sub
-----------------
I would like to have the windows names of running programs go to the cboProcess. To try and stop the c: Programs/blah/blah/blah.exe and only show the exe's in the cboProcess. Any idea's? Yes I am a newbie! Thanks

Error SQL Command, Will Give VbNullString?
Hi

From the SQL command that I had written, if the SQL command return to no result,is it consider vbNullString? In my Vb coding, I found that even though I enter the wrong username and password, the login is still successful. I think the main problem is the vbNullString? Need help...

Or is there any better way to compare and match the username and password that we key in with the database? Thank you.


VB Code:
Private Sub cmdLogin_Click()Dim bCombo As BooleanbCombo = functCheckInput() If bCombo = True Then    bCombo = functSelectQuery()    If bCombo = True Then        MsgBox ("Login Successfully")    Else        MsgBox ("Login Failed!")    End IfElse    MsgBox ("Invalid Input!")End If End Sub



VB Code:
Public Function functCheckInput() As Boolean If txtUsername.Text = vbNullString Then    functCheckInput = FalseElseIf txtpassword.Text = vbNullString Then    functCheckInput = FalseElse    functCheckInput = TrueEnd If End Function



VB Code:
Public Function functSelectQuery()Dim adoRS7 As ADODB.RecordsetSet adoRS7 = New ADODB.RecordsetDim strSQL As StringDim bResult As StringDim bReturn As Boolean bReturn = functConnectDatabase()     strSQL = "SELECT Username,Password FROM Employee WHERE Username= '"    strSQL = strSQL & txtUsername.Text & "' AND Password= '"    strSQL = strSQL & txtpassword.Text & "'"    adoRS7.Source = strSQL    adoRS7.CursorType = adOpenForwardOnly    adoRS7.ActiveConnection = adoConn    adoRS7.Open    Do While Not adoRS7.EOF        adoRS7.MoveNext    Loop    adoRS7.Close    Set adoRS7 = Nothing        If strSQL <> vbNullString Then        functSelectQuery = True    Else        functSelectQuery = False    End If    End Function

CreateDocumentFromUrl(txtURL.Text, VbNullString), How To Stop Popup Windows?
I just want to use only MSHMTL HTMLDocument object to get html source without webbrowser.

How can I stop the popup windows?

Set objDocument = objMSHTML.createDocumentFromUrl(txtURL.Text, vbNullString)

Copyright 2005-08 www.BigResource.com, All rights reserved