Results 1 to 26 of 26

Thread: [RESOLVED] Var being used - help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Resolved [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

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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"

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    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......

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Var being used - help

    Yep I did that m8, try it n see..

  6. #6
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    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

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    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]

  10. #10
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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"

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    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.

  12. #12
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Var being used - help

    Well that didn't help @dun... still blank lisstview

  14. #14
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Var being used - help

    Quote Originally Posted by chris-2k View Post
    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.

    Name:  a.png
Views: 174
Size:  45.5 KB

    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!

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Var being used - help

    OooooO Thanks guys, now can u help remove dupes

  16. #16
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Var being used - help

    If I move the listview outside the loop, all the progName's show as 1 item.......

  18. #18
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Var being used - help

    I tried that at 1st, no change...

  20. #20
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Var being used - help

    vb.net Code:
    1. Public Class Form1
    2.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    3.         For Each ln In IO.File.ReadLines("C:\InstallCFG.ini")
    4.             If ln.ToLower.StartsWith("prog name") Then
    5.                 ListView1.Items.Add(ln.Substring(ln.IndexOf(":"c) + 1)) ' a faster and more efficient option than splitting
    6.                 TextBox1.AppendText(ln.Substring(ln.IndexOf(":"c) + 1) & vbCrLf)
    7.             ElseIf ln.ToLower.StartsWith("description") Then
    8.                 ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(ln.Substring(ln.IndexOf(":"c) + 1))
    9.             End If
    10.         Next
    11.     End Sub
    12. 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!

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Var being used - help

    That don't work, it don't like
    Code:
    For Each ln In IO.File.ReadLines("C:\InstallCFG.ini")

  22. #22
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    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......

  24. #24
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Var being used - help

    Sorry I meant file size....

  26. #26
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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
  •  



Click Here to Expand Forum to Full Width