|
-
May 6th, 2013, 10:01 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Var being used - help
Hi,
Can someone throw me a bone, I don't know a fix for this:
Code:
Warning 1 Variable 'progName' is used before it has been assigned a value. A null reference exception could result at runtime. H:\X17-59183\PostInstall\PostInstall\SelectPrograms.vb 29 42 PostInstall
Here's me code:
Code:
Public Class SelectPrograms
Dim Ver As String = " - v1.0.1 Beta 2"
Private Sub SelectPrograms_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
Me.Text = "Post Install By Chris2k" + Ver
Dim iniFile As String = Application.StartupPath + "\Start\InstallCFG.ini"
Dim sR As New IO.StreamReader(iniFile)
Dim line, progName As String
Dim ReadResult() As String
If Not (System.IO.File.Exists(iniFile)) Then
MessageBox.Show("The programs opted for this OS can't be installed as the InstallCFG.ini has not been included...")
End If
line = sR.ReadLine()
Do While Not (line Is Nothing)
ReadResult = line.Split(":") 'Split line at :
If (ReadResult(0).ToLower() = "prog name") Then
progName = TextBox1.Text + ReadResult(1) + Environment.NewLine
End If
line = sR.ReadLine() 'Move on to the next line.
Dim Item As New ListViewItem(progName)
Item.SubItems.Add("progDesc")
Item.SubItems.Add("Size")
ListView1.Items.Add(Item)
Loop
sR.Close()
End Sub
End Class
-
May 6th, 2013, 10:07 AM
#2
Re: Var being used - help
its because progName is outside the do while...
just do this
Dim progName As String = ""
or remove the Dim progName from up top and do this
Dim progName as String = TextBox1.Text + ReadResult(1) + Environment.NewLine
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
May 6th, 2013, 10:44 AM
#3
Thread Starter
Hyperactive Member
Re: Var being used - help
I did the 1st solution u said, now all 30 progName's show as blaank/empty in the Textbox1 and listview1......
-
May 6th, 2013, 10:57 AM
#4
Re: Var being used - help
Er ... how did you manage that? All you had to do was replace ....
Dim line, progName As String
... with ...
Dim line As String = ""
Dim progname As String = ""
Oh, and there doesn't appear to be anything assigned to TextBox1.Text so it's not terribly surprising if it doesn't show anything.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 6th, 2013, 11:07 AM
#5
Thread Starter
Hyperactive Member
Re: Var being used - help
Yep I did that m8, try it n see..
-
May 6th, 2013, 11:16 AM
#6
Frenzied Member
Re: Var being used - help
Code:
Public Class SelectPrograms
Dim Ver As String = " - v1.0.1 Beta 2"
Private Sub SelectPrograms_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
Me.Text = "Post Install By Chris2k" + Ver
Dim iniFile As String = "Start\InstallCFG.ini"
using sR As New IO.StreamReader(iniFile)
Dim progName As String=string.empty
Dim ReadResult() As String
If Not (System.IO.File.Exists(iniFile)) Then
MessageBox.Show("The programs opted for this OS can't be installed as the InstallCFG.ini has not been included...")
End If
Dim line As String = sR.ReadLine()
Do While line IsNot Nothing
ReadResult = line.Split(":") 'Split line at :
If (ReadResult(0).ToLower() = "prog name") Then
progName = TextBox1.Text & ReadResult(1)' & Environment.NewLine
End If
line = sR.ReadLine() 'Move on to the next line.
Dim Item As New ListViewItem(progName)
Item.SubItems.Add("progDesc")
Item.SubItems.Add("Size")
ListView1.Items.Add(Item)
Loop
End using
End Sub
End Class
-
May 6th, 2013, 11:21 AM
#7
Thread Starter
Hyperactive Member
Re: Var being used - help
Just showing as empty/blank in the listview1....
Code:
Public Class SelectPrograms
Dim Ver As String = " - v1.0.1 Beta 2"
Private Sub SelectPrograms_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
Me.Text = "Post Install By Chris2k" + Ver
Dim iniFile As String = Application.StartupPath + "\Start\InstallCFG.ini"
Dim sR As New IO.StreamReader(iniFile)
Dim line As String = ""
Dim progName As String = ""
Dim ReadResult() As String
If Not (System.IO.File.Exists(iniFile)) Then
MessageBox.Show("The programs opted for this OS can't be installed as the InstallCFG.ini has not been included...")
End If
line = sR.ReadLine()
Do While Not (line Is Nothing)
ReadResult = line.Split(":") 'Split line at :
If (ReadResult(0).ToLower() = "prog name") Then
progName = TextBox1.Text + ReadResult(1)
TextBox1.Text = progName
End If
line = sR.ReadLine() 'Move on to the next line.
Dim Item As New ListViewItem(progName)
Item.SubItems.Add("progDesc")
Item.SubItems.Add("Size")
ListView1.Items.Add(Item)
Loop
sR.Close()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
End ClassPublic Class SelectPrograms
Dim Ver As String = " - v1.0.1 Beta 2"
Private Sub SelectPrograms_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
Me.Text = "Post Install By Chris2k" + Ver
Dim iniFile As String = Application.StartupPath + "\Start\InstallCFG.ini"
Dim sR As New IO.StreamReader(iniFile)
Dim line As String = ""
Dim progName As String = ""
Dim ReadResult() As String
If Not (System.IO.File.Exists(iniFile)) Then
MessageBox.Show("The programs opted for this OS can't be installed as the InstallCFG.ini has not been included...")
End If
line = sR.ReadLine()
Do While Not (line Is Nothing)
ReadResult = line.Split(":") 'Split line at :
If (ReadResult(0).ToLower() = "prog name") Then
progName = TextBox1.Text + ReadResult(1)
TextBox1.Text = progName
End If
line = sR.ReadLine() 'Move on to the next line.
Dim Item As New ListViewItem(progName)
Item.SubItems.Add("progDesc")
Item.SubItems.Add("Size")
ListView1.Items.Add(Item)
Loop
sR.Close()
End Sub
End Class
-
May 6th, 2013, 11:29 AM
#8
Re: Var being used - help
So, let's see a sample CFG.ini file. We can't know what you're attempting to read otherwise.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 6th, 2013, 11:36 AM
#9
Thread Starter
Hyperactive Member
Re: Var being used - help
Sample .ini:
[code]##############################################################################
Force Install:
Install Order:1
Prog Name:Adobe Reader X 11.0.02
Description:
Installer File:Install\Apps\AcroRdrX-11.0.02.exe
##############################################################################
Force Install:
Install Order:2
Prog Name:Adobe Photoshop CS5 Extended Edition
Description:
Installer File:Install\Apps\Adobe_Photoshop_CS5_Extended_Edition_Silent_Chris2k.exe
##############################################################################
[code]
-
May 6th, 2013, 11:47 AM
#10
Re: Var being used - help
is the INI file in the debug BIN folder? (When you run the app, its going to look in the debug bin folder and not in the projects folder where your SLN is)
Dim iniFile As String = Application.StartupPath + "\Start\InstallCFG.ini"
better to put it in a place like "C:\start\" for now so your app always looks in the same place
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
May 6th, 2013, 12:01 PM
#11
Thread Starter
Hyperactive Member
Re: Var being used - help
Yeh my ini is in "blah\Debug\Start\InstallCFG.ini".. However that's no the issue, TextBox1 gets the info but listview1 isblank...
Last edited by chris-2k; May 6th, 2013 at 12:05 PM.
-
May 6th, 2013, 12:02 PM
#12
Re: Var being used - help
Right, first problem. Delete Me.Show() Your results are going to another instance of the form and therefore can't be seen!
Second problem, now you can see the results, they're probably not what you want. Have a think about why.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 6th, 2013, 12:15 PM
#13
Thread Starter
Hyperactive Member
Re: Var being used - help
Well that didn't help @dun... still blank lisstview
-
May 6th, 2013, 12:29 PM
#14
Re: Var being used - help
 Originally Posted by chris-2k
Well that didn't help @dun... still blank lisstview
Your code, with Me.Show deleted. Your sample, post #9, saved to file C:\InstallCFG.ini and file address amended to absolute.

Rubbish results but clearly visible ones!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 6th, 2013, 12:56 PM
#15
Thread Starter
Hyperactive Member
Re: Var being used - help
OooooO Thanks guys, now can u help remove dupes
-
May 6th, 2013, 01:38 PM
#16
Re: Var being used - help
The problem is that you are adding a listviewitem on every line of the file, whether or not it is relevant. You need to test the content of the line and create an item when creating an item is what the content merits.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 6th, 2013, 01:49 PM
#17
Thread Starter
Hyperactive Member
Re: Var being used - help
If I move the listview outside the loop, all the progName's show as 1 item.......
-
May 6th, 2013, 02:06 PM
#18
Re: Var being used - help
Don't move it out of the loop, move it into the If!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 6th, 2013, 02:15 PM
#19
Thread Starter
Hyperactive Member
Re: Var being used - help
I tried that at 1st, no change...
-
May 6th, 2013, 02:39 PM
#20
Re: Var being used - help
vb.net Code:
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
For Each ln In IO.File.ReadLines("C:\InstallCFG.ini")
If ln.ToLower.StartsWith("prog name") Then
ListView1.Items.Add(ln.Substring(ln.IndexOf(":"c) + 1)) ' a faster and more efficient option than splitting
TextBox1.AppendText(ln.Substring(ln.IndexOf(":"c) + 1) & vbCrLf)
ElseIf ln.ToLower.StartsWith("description") Then
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(ln.Substring(ln.IndexOf(":"c) + 1))
End If
Next
End Sub
End Class
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 6th, 2013, 02:53 PM
#21
Thread Starter
Hyperactive Member
Re: Var being used - help
That don't work, it don't like
Code:
For Each ln In IO.File.ReadLines("C:\InstallCFG.ini")
-
May 6th, 2013, 03:01 PM
#22
Re: Var being used - help
You pasted ion my file address and didn't change it for your own, didn't you?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 6th, 2013, 03:27 PM
#23
Thread Starter
Hyperactive Member
Re: Var being used - help
Yep m8, working now, tyvm for help.......
Hmm b4 I mark thread, can I copy the if for the description and add to listview as subitem......
-
May 6th, 2013, 03:58 PM
#24
Re: Var being used - help
Er ... did that already in Line 7.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 6th, 2013, 05:09 PM
#25
Thread Starter
Hyperactive Member
Re: Var being used - help
Sorry I meant file size....
-
May 6th, 2013, 06:05 PM
#26
Re: Var being used - help
Yup. The only reason I didn't put size in is cos it didn't appear in the file sample. But if it's the same format then just add another copy of the ElseIf with "size" instead of "description".
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
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
|