locked
Can anyone give me a leg up? RRS feed

  • Question

  • Hello,

    I'm trying to learn Visual Basic using a couple of books. Where I'm struggling the most is with what I want to do.

    Basically, all I want to try out is a simple lottery stat program - read the files, import it to a database, then do a simple frequency count. I'm sure it's really simple but when you're starting from scratch with the programming it's a mountain to climb and tbh, I'm getting nowhere.

    The books have nice little examples of various things but to me they are pretty meaningless. Employee records and such simply don't seem that relevant so I thought I'd like to mess about to try to learn programming using something that is - a little lotto stats program. Which is where I am struggling since the database stuff is pretty advanced (for an absolute beginner) and reading csv files may as well be going to the moon!

    What I want to do is read some of these csv's from the UK National Lotto site (Lotto and Euromillions):
    http://www.national-lottery.co.uk/player/files/Lotto.csv
    http://www.national-lottery.co.uk/player/files/EuroMillions.csv

    I then want to place them into a database and do a stat count on each - y'know, frequency of each number type thing. That's it.

    Can anyone help me out to help me kick off my Visual Basic programming please?
     
    Thanks!
    • Edited by bbc_basic Friday, October 10, 2008 11:58 AM
    Friday, October 10, 2008 11:56 AM

Answers

  • I think the best thing you should do is practically forget the stuff you learnt in bbc basic. I have a guy in my college class moving up from vb6 and he's trying to think the vb6 way and it simply doesnt work.

    As for the code Ill comment the bits i know for sure:

    Option Strict On  = Essential for anyday vb.net program. Basically says you have to do everything properly.

    Module Module1 = Tells the compilar you are going to make a module called Module1

        Sub Main()      =  Tells the Compilar that you are going to have a subroutine and your going to call it main.
            Dim ConnString As String =  Dim is a decleration statement. Syntax goes Dim <Name of the variable> As <Data Type eg string/int/char)

    Tony has kindly commented the rest of the code so hopefully it makes more sense now :)

    there are some links in this thread linking to vb.net tutorials

    http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835

    hth,

    Stuart B.

    • Proposed as answer by Stueh Tuesday, October 14, 2008 9:17 AM
    • Marked as answer by Martin Xie - MSFT Wednesday, October 15, 2008 3:01 AM
    Friday, October 10, 2008 9:08 PM
  •  Hi again

    Sorry if I seemed a little blunt in my last reply,

    Anyways,
    this piece of code will allow you to import you CSV file into a dataset via a dataadapter.  Hope this helps you on your way.

    Kind regards

    TSB


    Option Strict On

    Module Module1

        Sub Main()
            Dim ConnString As String

            'Data source is the directory where your lotto files will exist
            ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                  "Data Source=" & "Z:\" & ";" & _
                      "Extended Properties=""Text;HDR=NO;"""

            'Create an OleDB connection and open it.
            Dim TextConn As New System.Data.OleDb.OleDbConnection(ConnString)
            TextConn.Open()

            'Create an adapter and use that to fill your dataset.
            Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from lotto.csv", TextConn)

            Dim ds As DataSet = New DataSet("CSVFiles")
            da.Fill(ds, "TestFile")

            'To do, use the information contained in your dataset here as you wish.
            '....

            TextConn.Close()
        End Sub

    End Module

    Friday, October 10, 2008 1:44 PM

All replies

  • Hey, I'm also learning visual basic.

    Try this site if you are really new to programming, it has helped me a lot, and I can recommend it with both thumps up. Since it helps you learn the core principles of programming.

    LearnVisualStudio

    Regards
    Marnus Kruger
    Friday, October 10, 2008 12:09 PM
  • It seems that you want to take on quite a challenge for one of your starting applications, why sql server? MS Access and/or MS Excel may be a better solution for what you require.  Import the data into Access and create some SQL queries to give the information you require.

    Kind regards

    TSB
    Friday, October 10, 2008 12:29 PM
  • moonborn said:

    Hey, I'm also learning visual basic.

    Try this site if you are really new to programming, it has helped me a lot, and I can recommend it with both thumps up. Since it helps you learn the core principles of programming.

    LearnVisualStudio

    Regards
    Marnus Kruger



    Thanks for the link but it's pretty much covered by the books I have. I was hoping someone could give me the code to kick off what I want to do.
    Friday, October 10, 2008 1:00 PM
  • Tony Smith-Brewster said:

    It seems that you want to take on quite a challenge for one of your starting applications, why sql server? MS Access and/or MS Excel may be a better solution for what you require.  Import the data into Access and create some SQL queries to give the information you require.

    Kind regards

    TSB


    Um, I don't have MS Access and SQL queries are, well, I'm not even that sure what they are, never mind how to do them.

    I've no idea why SQL Server. I just want to push the csv's into a database, whichever is the most suitable that comes with Visual Basic 2008 Express. The idea behind that is it would mean the csv files would only need to be accessed online as required (i.e. once) and the data manipulation would get done via the database, if that makes sense?

    As to the 'challenge' - it's a mountain as far as I'm concerned and one I am presently unable to climb. It's very discouraging when all I want to do is make a simple stat program but the only way I can see to do it is, if you like, at the pinnacle of the mountain and therefore outwith my reach.

    I guess I'm like everyone else - if I have a working example of something that interests me I can play about with it and try to learn how to program by putting 'bells and whistles' on it.
    Friday, October 10, 2008 1:11 PM
  •  Hi again

    Sorry if I seemed a little blunt in my last reply,

    Anyways,
    this piece of code will allow you to import you CSV file into a dataset via a dataadapter.  Hope this helps you on your way.

    Kind regards

    TSB


    Option Strict On

    Module Module1

        Sub Main()
            Dim ConnString As String

            'Data source is the directory where your lotto files will exist
            ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                  "Data Source=" & "Z:\" & ";" & _
                      "Extended Properties=""Text;HDR=NO;"""

            'Create an OleDB connection and open it.
            Dim TextConn As New System.Data.OleDb.OleDbConnection(ConnString)
            TextConn.Open()

            'Create an adapter and use that to fill your dataset.
            Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from lotto.csv", TextConn)

            Dim ds As DataSet = New DataSet("CSVFiles")
            da.Fill(ds, "TestFile")

            'To do, use the information contained in your dataset here as you wish.
            '....

            TextConn.Close()
        End Sub

    End Module

    Friday, October 10, 2008 1:44 PM
  • Hi,

    I didn't think you were being blunt. :)

    Sorry, but what does that do? I copied it into a module on a WindowsForm but tbh, I've no idea what it's supposed to do or make it work. :/  Does that access the csv file on the website?

    When I say I'm a beginner, I really mean, beginner. Perhaps a better word would be 'clueless.' When I learned BASIC in the early days (BBC Basic type stuff) I found the best way to learn more extensive programming was to use an existing program to figure out what was happening and to then build upon and adapt it until I'd become fairly proficient at creating my own original ones.

    With this, er, modern stuff, I'm so far out my depth its not funny. Everything seems to be a mountainous learning curve! I've learned my way around the IDE and can create a few elementary routines but databases and csv's appear to be an entire discipline in their own right. I guess if I had a background in at least one aspect of programming it wouldn't be such a nightmare but as I don't, it is!

    I was hoping someone would take pity on me and give me the code to do what I've described to give me a leg up to get me started. Having said that, I know what it's like when it looks like someone is being lazy asking other people to do the work for them when the answers are 'out there.' I guess I'm just getting too old for learning!

    Thanks for helping out. I appreciate it. :)
    Friday, October 10, 2008 7:30 PM
  • I think the best thing you should do is practically forget the stuff you learnt in bbc basic. I have a guy in my college class moving up from vb6 and he's trying to think the vb6 way and it simply doesnt work.

    As for the code Ill comment the bits i know for sure:

    Option Strict On  = Essential for anyday vb.net program. Basically says you have to do everything properly.

    Module Module1 = Tells the compilar you are going to make a module called Module1

        Sub Main()      =  Tells the Compilar that you are going to have a subroutine and your going to call it main.
            Dim ConnString As String =  Dim is a decleration statement. Syntax goes Dim <Name of the variable> As <Data Type eg string/int/char)

    Tony has kindly commented the rest of the code so hopefully it makes more sense now :)

    there are some links in this thread linking to vb.net tutorials

    http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835

    hth,

    Stuart B.

    • Proposed as answer by Stueh Tuesday, October 14, 2008 9:17 AM
    • Marked as answer by Martin Xie - MSFT Wednesday, October 15, 2008 3:01 AM
    Friday, October 10, 2008 9:08 PM
  • Stueh said:

    I think the best thing you should do is practically forget the stuff you learnt in bbc basic. I have a guy in my college class moving up from vb6 and he's trying to think the vb6 way and it simply doesnt work.

    As for the code Ill comment the bits i know for sure:

    Option Strict On  = Essential for anyday vb.net program. Basically says you have to do everything properly.

    Module Module1 = Tells the compilar you are going to make a module called Module1

        Sub Main()      =  Tells the Compilar that you are going to have a subroutine and your going to call it main.
            Dim ConnString As String =  Dim is a decleration statement. Syntax goes Dim <Name of the variable> As <Data Type eg string/int/char)

    Tony has kindly commented the rest of the code so hopefully it makes more sense now :)

    there are some links in this thread linking to vb.net tutorials

    http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835

    hth,

    Stuart B.



    Thanks for that. :)

    Oh, I figured out when I started trying to learn this that my grasp of programming was lamentable and the old stuff I knew was pretty useless. :) The only thing I can hang onto was what I learned regarding logic but even that's completely out of date. Helpful in some ways but outdated.

    I think that's why I'm finding this so frustrating and discouraging. I know what I want to do but don't have a clue how to do it in the modern environment. I can write a few rudimentary routines but when it comes to today's modern databases and csv's I seem to develop a mental block, probably because it appears to be a whole field in its own right, requiring a whole additional set of skills and when you're starting off at the beginning to relearn everything it's like adding another mountain on the path to the first mountain, if you know what I mean? You have to climb half-way up the first one then come back down and go climb another one before you can start climbing the first one again.

    Is what I want to do with this little stat program actually much more complicated than I think it is? I mean, I know to me it seems ludicrously difficult but I thought in essence it appeared a fairly straightforward thing to do... if you know how to do it. Is it uber-complicated or relatively simple?
    Saturday, October 11, 2008 11:49 AM
  • I had a brainwave (never a good thing usually, lol) and posted the job on a Freelance Programmer website! I know, I know, it's 'cheating' but I think it's the only way I'm ever going to get going with this thing.

    Thanks for your help everyone! I really do appreciate it. :)
    Saturday, October 11, 2008 6:44 PM