The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

Anyone know visual basic?

override367override367 ALL minionsRegistered User regular
edited May 2011 in Help / Advice Forum
I'm trying to make a program for a class, or rather help someone make a program for a class. We need to take series of numbers from a text file separated by zeros and calculate the average of each series, along with an average of all the averages

It's a database class and I don't know hardly anything about VB so I'm flummoxed and cannot find the answer online

override367 on

Posts

  • DemerdarDemerdar Registered User regular
    edited May 2011
    Do you have to do it in visual basic? If you have access to MATLAB you can do that probably in a couple of lines.

    Demerdar on
    y6GGs3o.gif
  • override367override367 ALL minions Registered User regular
    edited May 2011
    the class is in visualbasic, just need to come up with the pseudocode for it and I figure something like:
    Accumulator1 Declaration
    Accumulator2 Declaration
    Counter1 Declaration
    Counter2 Declaration

    Loadtextfile (numbers.txt)
    Do while not end of file
    if zero
    OutputAverageText = (accumulator1/counter1)
    set accumulator1 to zero
    set counter1 to zero
    else
    count
    accumulate
    endloop


    Loadtextfile (averageoutput.txt)
    Do while not end of file
    Run accumulator2
    Run counter2
    endloop

    Averageaverageoutput to text = (accumulator2/counter2)

    Keep in mind I really don't have the foggiest idea about how to actually do this

    override367 on
  • TerrendosTerrendos Decorative Monocle Registered User regular
    edited May 2011
    Do you need to use a 0 to delineate the difference? I know I've written VB codes that read in comma delineated files and stored them into an array.

    That code looks pretty unfamiliar though, looks like they may have changed some of the syntax since then.

    Terrendos on
  • aperlscriptaperlscript Registered User regular
    edited May 2011
    First, go to your kitchen, and find two forks. Stick one in your left eye, and the other in your right eye. Now you're ready to begin.

    I'd go with pseudo code more like this:
    # this array will hold the averages of each line
    Array allAverages
    
    foreach line in file
        Array numbers = Split(line, "0")
        Integer average = Average(numbers)
        Print(average)
        AddToArray(allAverages, average)
    end foreach
    
    Print(Average(allAverages))
    

    The Split() function is documented here. I'm sure VB has some kind of Print() function that you can use in place of what I call "Print". The Average() and AddToArray() functions probably don't exist, but you can google around and see how others have done these.

    http://www.google.com/search?q=visual+basic+arrays
    http://www.google.com/search?q=visual+basic+average+of+an+array

    aperlscript on
  • tinwhiskerstinwhiskers Registered User regular
    edited May 2011
    If I'm understanding this right:
    your file wrote:
    10203040506070809
    204060802040608
    907050301090705

    This looks right: haven't tried it, but its your HW.

    http://www.fryan0911.com/2009/05/vbnet-how-to-read-csv-file-into-array.html


    replace

    strline = strlines(0).Split(",") with strline = strlines(0).Split("0") , and you should have it.

    once you have it into an array, loops and arithmetic to get your averages.(make sure its average of averages vs average of all the numbers).

    Also who the fuck separates numbers with a number?

    tinwhiskers on
    6ylyzxlir2dz.png
  • PailryderPailryder Registered User regular
    edited May 2011
    you know, when you want to separate the 1s from the 0s because 0s are really nothing and can be thrown away :)

    Pailryder on
  • Sir Headless VIISir Headless VII Registered User regular
    edited May 2011
    I assume they aren't going to be dicks and have a number series with a 0 or like 10 or 1000 in it are they? Or even worse 1010.

    Sir Headless VII on
    Steam - Backpack - Bnet: SirHeadless #1154
    7KEFduI.jpg
  • Mr_GrinchMr_Grinch Registered User regular
    edited May 2011
    Wouldn't that be absolutely impossible? Quick example with just 1s and 0s

    This: 10010010101010101010101100001010

    Could be:
    10 010 0101 0101 01 010101 011000 01 010
    So 10,10,101,101,1,10101,11000,1,10

    or
    10 010 01 01 01 01 0101 0101 011000 01010
    So 10,10,1,1,1,1,101,101,11000,1010

    Two completely different sets of numbers. Which would make it impossible.

    Mr_Grinch on
    Steam: Sir_Grinch
    PSN: SirGrinchX
    Oculus Rift: Sir_Grinch
  • TejsTejs Registered User regular
    edited May 2011
    I'm curious why a database class would make you program in VB instead of you know, T-SQL or something with tables.

    The above mentioned pseudo code will work effectively; if you're using VB.NET, and not just VB, there are helper methods (extension methods in this case) that can greatly simplify your life (code provided in C#, but you can get the drift)
    // Splits a string on the specific character into an array and removes elements that are string.Empty
    myString.Split(new char[] { '0' }, StringSplitOptions.RemoveEmptyEntries)
    
    // Requires using System.Linq;
    myArray.Average();
    

    Tejs on
  • splashsplash Registered User regular
    edited May 2011
    Tejs wrote: »
    I'm curious why a database class would make you program in VB instead of you know, T-SQL or something with tables.

    If the class is using mostly Access to teach database concepts and such then VB is very likely as it's built-in. My first database class did this.

    splash on
  • L Ron HowardL Ron Howard The duck MinnesotaRegistered User regular
    edited May 2011
    Show you the worst way possible to do things at first, so that you greatly appreciate the better things as you progress?

    L Ron Howard on
Sign In or Register to comment.