Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > Visual Basic: Can't get the program to work.
 

Visual Basic: Can't get the program to work.

I am not recieving any errors, but the program is not doing what I had expected. I wish to make a program that randomly takes characters (well, not completely randomly. I used the table of letter frequency from wikipedia andincluded that data in my program by figuring out the max for the random numbers from the percentages in the wikipedia chart.) and adds them to a long list of characters ands saves the file every 5 minutes.I have calculated the timer interval so that the number of miliseconds shown is equal to 5 minutes. I am getting the textwindow, and it is showing (rather rapidly, as I need it to be) a long random list of characters (including spaces). The problems are (A) I am having difficulty saving the text as a file. You'll find the code that is supposed to do that at the bottom. The other problem I am having is once so many characters are added, the ones at the top start disappearing. I would scroll to the top, and each time I did so the letters at the top had changed (this is all during the same test), but I need all characters to be stored when the file saves. Granted, I haven't actually seen one of the saved files as I have not figured out how to make that work. One other thing, not sure if it's important, I haven't run a published version yet. I've only been running the debug builds. Does that affect how it handles actions with files? I could really use advice, as I'm pretty new to programming. The entire code is below.


Module RandomModule

    Dim X, Y, contents As Primitive

    Sub Main()

        X = 1

        Y = 1

        While X = Y

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(12) = 1 Then

                TextWindow.Write("A")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(67) = 1 Then

                TextWindow.Write("B")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(36) = 1 Then

                TextWindow.Write("C")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(24) = 1 Then

                TextWindow.Write("D")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(8) = 1 Then

                TextWindow.Write("E")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(45) = 1 Then

                TextWindow.Write("F")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(50) = 1 Then

                TextWindow.Write("G")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(16) = 1 Then

                TextWindow.Write("H")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(14) = 1 Then

                TextWindow.Write("I")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(654) = 1 Then

                TextWindow.Write("J")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(130) = 1 Then

                TextWindow.Write("K")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(25) = 1 Then

                TextWindow.Write("L")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(42) = 1 Then

                TextWindow.Write("M")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(15) = 1 Then

                TextWindow.Write("N")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(13) = 1 Then

                TextWindow.Write("O")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(52) = 1 Then

                TextWindow.Write("P")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(1053) = 1 Then

                TextWindow.Write("Q")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(17) = 1 Then

                TextWindow.Write("R")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(16) = 1 Then

                TextWindow.Write("S")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(11) = 1 Then

                TextWindow.Write("T")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(36) = 1 Then

                TextWindow.Write("U")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(101) = 1 Then

                TextWindow.Write("V")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(42) = 1 Then

                TextWindow.Write("W")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(667) = 1 Then

                TextWindow.Write("X")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(51) = 1 Then

                TextWindow.Write("Y")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(1351) = 1 Then

                TextWindow.Write("Z")

            End If

            If Microsoft.SmallBasic.Library.Math.GetRandomNumber(6) = 1 Then

                TextWindow.Write(" ")

            End If

        End While



        Timer.Interval = 18000000

        AddHandler Timer.Tick, AddressOf Time





    End Sub

    Sub Time()

        X = X + 1

        contents = TextWindow.Read()

        File.AppendContents("c:\random\test.txt", contents)

        TextWindow.Clear()

        Y = Y + 1

    End Sub

End Module



cpuguy89  Friday, November 20, 2009 10:39 PM

What is the exact variety or flavor of Visual Basic that you are using? A number of items here, such as the type Primitive, are not native to Visual Basic .Net, and they may have an impact on the problem you are seeing.Is it possible that this is a more suitable location for your query:

http://social.msdn.microsoft.com/Forums/en-US/smallbasic/threads

Also, what is the problem with the file? Are you sure that the file is properly closed when you look at the contents?

Acamar  Friday, November 20, 2009 11:01 PM

This is definitely not SmallBasic, which use line numbers like GWBasic.

The timer is doing absolutely nothing, based upon the posted code.
The timer is never started, and even if it were the code is stuck inside of the while loop.


Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Friday, November 20, 2009 11:40 PM
The program listing provided by OP is consistent with Small Basic syntax, and it uses the Small Basic math library, so it seems a pretty good guess that it is a Small Basic program. See, for instance:

http://smallbasic.com/program/?NXP803
Acamar  Saturday, November 21, 2009 12:02 AM

We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by clicking "Change Type" at the top of the thread. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Jeff Shan  Thursday, November 26, 2009 5:57 AM

You can use google to search for other answers

Custom Search

More Threads

• Connecting a OPC-Server in VB.Net
• Number Character or Alpha Character Validation
• Visual Basic 6 GridProps
• search for specific files on a drive and handling of exceptions
• How to read hard drive info
• jop page copy number in queue ?
• Using Picture Box properties as variables
• Rational Class and Square Root Loops
• Use Compare?
• Copy directory and show progress