experchange > vb.* > vb.general.discussion

John K.Eason (01-01-70, 02:00 AM)
In article <14509b4a-8688-4c71-b716-8ff81cbc3f82>,
curtraydavis () wrote:

> *From:* curtraydavis
> *Date:* Fri, 17 Jan 2020 19:22:27 -0800 (PST)
> I am attempting to execute a batch file with two arguments from vb6.
> Shell ("c:\tftp\Createplkstart.txt.bat " & strMsg & " " & cfgSaved
> & switchIP)
> however it seems to drop the second and third arguments.
> If I do a msgbox :
> MsgBox "Createplkstart.txt.bat " & strstart & " " & cfgSaved
> it returns two lines with the space " ".
> thanks for any advice What does


debug.print strMsg & "<"

show? - It sounds as if strMsg contains a newline character.

In cases like that I'd be inclined to put the whole Shell command into a string
variable and then debug.print the contents to see what the string actually contains
before trying to run it.
curtraydavis (01-18-20, 05:22 AM)
I am attempting to execute a batch file with two arguments from vb6.

Shell ("c:\tftp\Createplkstart.txt.bat " & strMsg & " " & cfgSaved & switchIP)

however it seems to drop the second and third arguments.

If I do a msgbox :

MsgBox "Createplkstart.txt.bat " & strstart & " " & cfgSaved

it returns two lines with the space " ".

thanks for any advice
Mayayana (01-18-20, 04:04 PM)
<curtraydavis> wrote

|I am attempting to execute a batch file with two arguments from vb6.
| Shell ("c:\tftp\Createplkstart.txt.bat " & strMsg & " " & cfgSaved &
switchIP)
| however it seems to drop the second and third arguments.
|
| If I do a msgbox :
| MsgBox "Createplkstart.txt.bat " & strstart & " " & cfgSaved
| it returns two lines with the space " ".

Since you didn't post the code that defines those variables,
how can anyone guess what the problem is? It sounds like
you're saying it returns " " & vbCrLf & " ". What does "Two
lines with the space" mean? Try posting the actual code and
the actual result.
curtraydavis (01-18-20, 04:19 PM)
On Friday, January 17, 2020 at 9:22:29 PM UTC-6, curtra...@gmail.com wrote:
> I am attempting to execute a batch file with two arguments from vb6.
> Shell ("c:\tftp\Createplkstart.txt.bat " & strMsg & " " & cfgSaved & switchIP)
> however it seems to drop the second and third arguments.
> If I do a msgbox :
> MsgBox "Createplkstart.txt.bat " & strstart & " " & cfgSaved
> it returns two lines with the space " ".
> thanks for any advice


Here is the code:

VERSION 5.00
Begin VB.Form Form1
Caption = "Get Cisco Switch Configs"
ClientHeight = 5775
ClientLeft = 120
ClientTop = 450
ClientWidth = 6375
Icon = "Form1.frx":0000
LinkTopic = "Form1"
ScaleHeight = 5775
ScaleWidth = 6375
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox Picture1
Height = 1380
Left = 120
Picture = "Form1.frx":57E2
ScaleHeight = 946.237
ScaleMode = 0 'User
ScaleWidth = 6075
TabIndex = 8
Top = 120
Width = 6135
End
Begin VB.CommandButton Command1
Caption = "Quit"
BeginProperty Font
Name = "Arial"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 3
Top = 5040
Width = 5655
End
Begin VB.ListBox switchIP
BeginProperty Font
Name = "Arial"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
ItemData = "Form1.frx":12F534
Left = 600
List = "Form1.frx":12F553
TabIndex = 2
Top = 2760
Width = 1335
End
Begin VB.TextBox cfgSaved
Alignment = 2 'Center
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 360
Left = 240
TabIndex = 1
Top = 3840
Width = 5895
End
Begin VB.CommandButton btngetconfigs
Caption = "Get Start Config"
BeginProperty Font
Name = "Arial"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 0
Top = 4440
Width = 2655
End
Begin VB.Frame Frame1
BackColor = &H80000016&
Height = 4455
Left = 120
TabIndex = 4
Top = 1560
Width = 6135
Begin VB.TextBox AutoTftp
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000016&
BorderStyle = 0 'None
DataField = "strMsg"
BeginProperty Font
Name = "Arial"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 3240
TabIndex = 10
Text = "Text1"
Top = 360
Width = 1695
End
Begin VB.CommandButton BtgGetLogs
Caption = "Get Switch Logs"
BeginProperty Font
Name = "Arial"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 3120
TabIndex = 9
Top = 2880
Width = 2655
End
Begin VB.Label Label6
Alignment = 2 'Center
BackColor = &H80000016&
Caption = "Your computer IP Address is: "
BeginProperty Font
Name = "Arial"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 7
Top = 360
Width = 3015
End
Begin VB.Label Label5
Alignment = 2 'Center
BackColor = &H80000016&
Caption = "Please select and click on the switch IP address below."
BeginProperty Font
Name = "Arial"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 6
Top = 840
Width = 5895
End
Begin VB.Label Label4
Alignment = 2 'Center
BackColor = &H80000016&
Caption = "Please name your new config or log file name below"
BeginProperty Font
Name = "Arial"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 5
Top = 1920
Width = 5895
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Form_Load()
strMsg = ""
strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")

For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IpAddress) Then
For i = LBound(IPConfig.IpAddress) To UBound(IPConfig.IpAddress)
If Not InStr(IPConfig.IpAddress(i), ":") > 0 Then
strMsg = strMsg & IPConfig.IpAddress(i) & vbCrLf
End If
Next
End If
Next
'MsgBox strMsg
AutoTftp = (strMsg)
End Sub

Private Sub btngetconfigs_Click()

strMsg = ""
strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")

For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IpAddress) Then
For i = LBound(IPConfig.IpAddress) To UBound(IPConfig.IpAddress)
If Not InStr(IPConfig.IpAddress(i), ":") > 0 Then
strMsg = strMsg & IPConfig.IpAddress(i) & vbCrLf
End If
Next
End If
Next
AutoTftp = (strMsg)

'MsgBox strMsg & " " & cfgSaved & switchIP
strstart = ((" " & strMsg & cfgSaved & switchIP))
MsgBox strstart
MsgBox "\c:\tftp\Createplkstart.txt.bat " & strstart & cfgSaved
'Shell ("c:\tftp\Createplkstart.txt.bat " & strMsg & " " & cfgSaved & switchIP)

'Shell ("c:\tftp\GetSwitchCFG.bat " & switchIP & " " & strMsg & switchIP)

'Shell ("C:\tftp\CopyToDesktop.bat " & cfgSaved)
End Sub

Private Sub BtgGetLogs_Click()

strMsg = ""
strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")

For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IpAddress) Then
For i = LBound(IPConfig.IpAddress) To UBound(IPConfig.IpAddress)
If Not InStr(IPConfig.IpAddress(i), ":") > 0 Then
strMsg = strMsg & IPConfig.IpAddress(i) & vbCrLf
End If
Next
End If
Next
AutoTftp = (strMsg)

'MsgBox strMsg & " " & cfgSaved & switchIP
Shell ("c:\tftp\Createplklog.txt.bat " & strMsg & " " & cfgSaved & switchIP)

Shell ("c:\tftp\GetSwitchLOG.bat " & switchIP & " " & cfgSaved & switchIP)

'Shell ("C:\tftp\CopyToDesktop.bat " & cfgSaved)
End Sub

Private Sub Command1_Click()

Shell ("C:\tftp\DeleteAll.bat")

Unload Me
End Sub

Thanks again for your help
curtraydavis (01-18-20, 04:48 PM)
On Friday, January 17, 2020 at 9:22:29 PM UTC-6, curtra...@gmail.com wrote:
> I am attempting to execute a batch file with two arguments from vb6.
> Shell ("c:\tftp\Createplkstart.txt.bat " & strMsg & " " & cfgSaved & switchIP)
> however it seems to drop the second and third arguments.
> If I do a msgbox :
> MsgBox "Createplkstart.txt.bat " & strstart & " " & cfgSaved
> it returns two lines with the space " ".
> thanks for any advice


VERSION 5.00
Begin VB.Form Form1
Caption = "Get Cisco Switch Configs"
ClientHeight = 5775
ClientLeft = 120
ClientTop = 450
ClientWidth = 6375
Icon = "Form1.frx":0000
LinkTopic = "Form1"
ScaleHeight = 5775
ScaleWidth = 6375
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox Picture1
Height = 1380
Left = 120
Picture = "Form1.frx":57E2
ScaleHeight = 946.237
ScaleMode = 0 'User
ScaleWidth = 6075
TabIndex = 8
Top = 120
Width = 6135
End
Begin VB.CommandButton Command1
Caption = "Quit"
BeginProperty Font
Name = "Arial"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 3
Top = 5040
Width = 5655
End
Begin VB.ListBox switchIP
BeginProperty Font
Name = "Arial"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
ItemData = "Form1.frx":12F534
Left = 600
List = "Form1.frx":12F553
TabIndex = 2
Top = 2760
Width = 1335
End
Begin VB.TextBox cfgSaved
Alignment = 2 'Center
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 360
Left = 240
TabIndex = 1
Top = 3840
Width = 5895
End
Begin VB.CommandButton btngetconfigs
Caption = "Get Start Config"
BeginProperty Font
Name = "Arial"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 0
Top = 4440
Width = 2655
End
Begin VB.Frame Frame1
BackColor = &H80000016&
Height = 4455
Left = 120
TabIndex = 4
Top = 1560
Width = 6135
Begin VB.TextBox AutoTftp
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000016&
BorderStyle = 0 'None
DataField = "strMsg"
BeginProperty Font
Name = "Arial"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 3240
TabIndex = 10
Text = "Text1"
Top = 360
Width = 1695
End
Begin VB.CommandButton BtgGetLogs
Caption = "Get Switch Logs"
BeginProperty Font
Name = "Arial"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 3120
TabIndex = 9
Top = 2880
Width = 2655
End
Begin VB.Label Label6
Alignment = 2 'Center
BackColor = &H80000016&
Caption = "Your computer IP Address is: "
BeginProperty Font
Name = "Arial"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 7
Top = 360
Width = 3015
End
Begin VB.Label Label5
Alignment = 2 'Center
BackColor = &H80000016&
Caption = "Please select and click on the switch IP address below."
BeginProperty Font
Name = "Arial"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 6
Top = 840
Width = 5895
End
Begin VB.Label Label4
Alignment = 2 'Center
BackColor = &H80000016&
Caption = "Please name your new config or log file name below"
BeginProperty Font
Name = "Arial"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 5
Top = 1920
Width = 5895
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Form_Load()
strMsg = ""
strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")

For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IpAddress) Then
For i = LBound(IPConfig.IpAddress) To UBound(IPConfig.IpAddress)
If Not InStr(IPConfig.IpAddress(i), ":") > 0 Then
strMsg = strMsg & IPConfig.IpAddress(i) & vbCrLf
End If
Next
End If
Next
'MsgBox strMsg
AutoTftp = (strMsg)
End Sub

Private Sub btngetconfigs_Click()

strMsg = ""
strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")

For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IpAddress) Then
For i = LBound(IPConfig.IpAddress) To UBound(IPConfig.IpAddress)
If Not InStr(IPConfig.IpAddress(i), ":") > 0 Then
strMsg = strMsg & IPConfig.IpAddress(i) & vbCrLf
End If
Next
End If
Next
AutoTftp = (strMsg)
'THESE NEXT THREE LINE ARE ME JUST TRYING TO FIGURE OUT WHY I CAN'T DO A SPACE
MsgBox strMsg & " " & cfgSaved & switchIP
strstart = strMsg & " " & cfgSaved & switchIP
MsgBox strstart
MsgBox "\c:\tftp\Createplkstart.txt.bat " & strstart & cfgSaved
'THIS ONE BELOW IS WHAT IS BEATING ME UP, WHY CAN'T I USE A SPACE OR AM I DOING 'IT WRONG
Shell ("c:\tftp\Createplkstart.txt.bat " & strMsg & " " & cfgSaved & switchIP)

Shell ("c:\tftp\GetSwitchCFG.bat " & switchIP & " " & strMsg & switchIP)

'Shell ("C:\tftp\CopyToDesktop.bat " & cfgSaved)
End Sub

Private Sub BtgGetLogs_Click()

strMsg = ""
strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")

For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IpAddress) Then
For i = LBound(IPConfig.IpAddress) To UBound(IPConfig.IpAddress)
If Not InStr(IPConfig.IpAddress(i), ":") > 0 Then
strMsg = strMsg & IPConfig.IpAddress(i) & vbCrLf
End If
Next
End If
Next
AutoTftp = (strMsg)

'MsgBox strMsg & " " & cfgSaved & switchIP
Shell ("c:\tftp\Createplklog.txt.bat " & strMsg & " " & cfgSaved & switchIP)

Shell ("c:\tftp\GetSwitchLOG.bat " & switchIP & " " & cfgSaved & switchIP)

'Shell ("C:\tftp\CopyToDesktop.bat " & cfgSaved)
End Sub

Private Sub Command1_Click()

Shell ("C:\tftp\DeleteAll.bat")

Unload Me
End Sub
Larry Serflaten (01-18-20, 07:06 PM)
curtra...@gmail.com wrote:
> I am attempting to execute a batch file with two arguments from vb6.
> Shell ("c:\tftp\Createplkstart.txt.bat " & strMsg & " " & cfgSaved & switchIP)
> however it seems to drop the second and third arguments.


I did not try any of your code, but I saw you were using WMI.

I would suggest you check to see if the strings you get from WMI
end with the null character <chr$(0)>. That might be an issue,
I am not sure, but its an easy check....

LFS
GS (01-18-20, 07:22 PM)
> curtra...@gmail.com wrote:
> I did not try any of your code, but I saw you were using WMI.
> I would suggest you check to see if the strings you get from WMI
> end with the null character <chr$(0)>. That might be an issue,
> I am not sure, but its an easy check....
> LFS


Yes it does; - all my WMI code uses the Trim() function for all query returns
so all I get back is the text!
GS (01-18-20, 09:12 PM)
Uh, I don't see where your variables get declared/defined, AND why so much
repetition of exact same code in so many places? Why not put it in a reusable
function that returns a string value with a simple call to it?

Option Explicit

'[Module Level Vars]
'-------------------
Dim msIPAddrs$, msAutoTftp$, msStart$, msCfgSaved$, msSwitchIP$

'[Form/Controls Defs]
'--------------------
Private Sub btnGetConfigs_Click()
Dim vAddrs, n&
If msIPAddrs = "" Then msIPAddrs = GetIpAddr()
vAddrs = Split(msIPAddrs, vbCrLf)
For n = LBound(vAddrs) To UBound(vAddrs)
'Do Config related stuff

Next 'n
End Sub

Private Sub btnGetLogs_Click()
Dim vAddrs, n&
If msIPAddrs = "" Then msIPAddrs = GetIpAddr()
vAddrs = Split(msIPAddrs, vbCrLf)
For n = LBound(vAddrs) To UBound(vAddrs)
'Do Logs related stuff

Next 'n
End Sub

Private Sub Form_Load()
msIPAddrs = GetIpAddr()
'Do Form related stuff

End Sub 'Form_Load

'[Support Defs]
'--------------
Function GetIpAddr$()
' Returns IP Addresses from WMI
Const sQuery$ = "Select * from Win32_NetworkAdapterConfiguration"
Const sCriteria$ = " WHERE IPEnabled = 'True'"

Dim vWMI, vSettings, vInfo, n&, saVals$()
Set vWMI = GetObject("WinMgmts:")
Set vSettings = vWMI.ExecQuery(sQuery & sCriteria)
For Each vInfo In vSettings
If Not IsNull(vInfo.IPAddress) Then
ReDim Preserve saVals(n + 1)
saVals(n) = Join(vInfo.IPAddress, "."): n = n + 1
End If
Next 'vInfo
GetIpAddr = Join(saVals, vbCrLf)
End Function 'GetIpAddr
Mayayana (01-18-20, 09:14 PM)
<curtraydavis> wrote

| Private Sub BtgGetLogs_Click()
|
|
| strMsg = ""
| strComputer = "."
|
| Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
| Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from
Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")
|
| For Each IPConfig In IPConfigSet
| If Not IsNull(IPConfig.IpAddress) Then
| For i = LBound(IPConfig.IpAddress) To UBound(IPConfig.IpAddress)
| If Not InStr(IPConfig.IpAddress(i), ":") > 0 Then
| strMsg = strMsg & IPConfig.IpAddress(i) & vbCrLf
| End If
| Next
| End If
| Next
| AutoTftp = (strMsg)
|
| 'MsgBox strMsg & " " & cfgSaved & switchIP

That code seems to work for me. But I notice
that you're adding vbCrLf on each round. I only
have one adaptor and it works as expected. In
the last msgbox I get:
\c:\tftp\Createplkstart.txt.bat 192.168.1.95

But if you have two adapters you're going to
get the vbCrLf in there. And if they're enabled but
IPv4 isn't then you might get empty values.

You seem to be mixing code for a system info
listing with code for shelling. I think you need
to sort the collection first, find a relevant IP
address if there is one, and only then build your
command line.
GS (01-18-20, 09:14 PM)
>> curtra...@gmail.com wrote:
> Yes it does; - all my WMI code uses the Trim() function for all query returns
> so all I get back is the text!


Note that OP's code handles this in an If Not IsNull()...Then construct!<g>
GS (01-18-20, 09:21 PM)
Since IP Addresses use the dot delimiter, change the function to use Pipe (or
whatever you like) instead...

Function GetIpAddr$()
' Returns IP Address from WMI
Const sQuery$ = "Select * from Win32_NetworkAdapterConfiguration"
Const sCriteria$ = " WHERE IPEnabled = 'True'"

Dim vWMI, vSettings, vInfo, n&, saVals$()
Set vWMI = GetObject("WinMgmts:")
Set vSettings = vWMI.ExecQuery(sQuery & sCriteria)
For Each vInfo In vSettings
If Not IsNull(vInfo.IPAddress) Then
ReDim Preserve saVals(n + 1)
saVals(n) = Join(vInfo.IPAddress, "|"): n = n + 1
End If
Next 'vInfo
GetIpAddr = Join(saVals, vbCrLf)
End Function 'GetIpAddr
Mayayana (01-18-20, 09:23 PM)
-
"GS" <gs> wrote

| > Yes it does; - all my WMI code uses the Trim() function for all query
returns
| > so all I get back is the text!
|
| Note that OP's code handles this in an If Not IsNull()...Then
construct!<g>
|

I think there's a mixup there. The IsNull applies
to the array of addresses. The code is saying
for each adapter, if there's an address array with
content, then if any of them are IPv4, then add
them to the list. There's no issue with Chr(0).
It looks like OP is getting no addresses, but the
loop puts in a vbCrLf, perhaps due to a blank address
for a connection with dynamic IP?

I use fixed IP on my system, rather than DHCP,
so I just get a simple return of the local IP address.
GS (01-18-20, 09:26 PM)
> <curtraydavis> wrote
[..]
> to sort the collection first, find a relevant IP
> address if there is one, and only then build your
> command line.


WMI Code Creator shows I have 6 adapters in this machine, but only 3 of them
have IP Adresses assigned. The code I posted only returns those 3 assigned IP
Addresses
Mayayana (01-19-20, 12:24 AM)
"GS" <gs> wrote

|
| WMI Code Creator shows I have 6 adapters in this machine, but only 3 of
them
| have IP Adresses assigned. The code I posted only returns those 3 assigned
IP
| Addresses
|
6 adapters?! I was thinking that if one is enabled
but had DHCP connection and isn't currently assigned,
then it might return only vbCrLf. I'm not sure. That's
all I could think of.

Why would you have 6 network adapters?
curtraydavis (01-19-20, 12:53 AM)
Thanks all for your input, I found the & vbCrLf was my problem,
I just removed and all works as I wanted.

strMsg = strMsg & IPConfig.IpAddress(i) & vbCrLf

Yes a lot of repetition because I didn't/don't know how put it in a reusable
function that returns a string value with a simple call to it.
I don't know vb well at all, I just stumble through until I accomplish my goal.

I'm sure that if/when I do these things my hundred lines of code could probably be accomplished with 25 lines.

I am would really like to know how to do the reusable function if you would have time to show me.

Thanks

Similar Threads