473,508 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading txt file

1 New Member
I'm working on a program for reading a txt file. the file is read and its data are sent to the viewers with an indeterminate cycle every minute.
I wanted to replace the sleep with a timer. I tried the same procedure under timers instead of under button1 but it does not work. how can I proceed with the change.

Public Class Form1
Dim disco1 As System.IO.File
Dim leggi1 As System.IO.StreamReader
Dim ms As Integer = 60000

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Size = Screen.PrimaryScreen.WorkingArea.Size
Me.Location = Screen.PrimaryScreen.WorkingArea.Location
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Button1.BackColor = Color.Red
Dim riga1 As String
Dim i As Integer
Do
leggi1 = disco1.OpenText("e:\rgb100.txt")
For i = 1 To 60
i = i + 1
riga1 = leggi1.ReadLine()
TextBox1.Text = riga1
ListBox1.Items.Add(riga1)

Application.DoEvents()
System.Threading.Thread.Sleep(ms)
Next i
Loop
End Sub
End Class
Nov 4 '18 #1
1 1676
JClinton
1 New Member
This Game Reads Text Files

Module Module1

Structure card 'shows layout

Dim name As String 'display the name as A word

Dim heading As Integer 'display heading as number

Dim shooting As Integer 'display shooting as number

Dim dribbling As Integer 'display dribbling as a number

Dim injury As Integer 'display injury as a number

End Structure 'ends the layout

Dim chosencategory As String

Dim whostarts As Integer = 0

Dim loseorwin As Integer = 0

Dim cards() As card

Dim amountofcards As String

Dim playershand() As card

Dim computershand() As card

Sub Main()

Dim playersize As String

playersize = amountofcards

GetMenuChoice() 'goes to the sub GetMenuChoice()

getdecksize() 'goes to the sub getdecksize()

getnameoffootballers() 'goes to the sub getnameoffootballers()

setattributes()

dealhands(amountofcards) 'goes to the sub dealhands(amountofcards)

If whostarts = 1 Then

menu2()

Else

menu3()

End If

Console.ReadLine()

End Sub

Sub menu2()

altshowtopcard()

shiftcards()

End Sub

Sub menu3()

showtopcard()

shiftcards()

End Sub

Sub DisplayMenu()

Console.WriteLine("Menu---------------------------------------------------------------------------")

Console.WriteLine("1.Play game--------------------------------------------------------------------")

Console.WriteLine("2.Quit-------------------------------------------------------------------------")

Console.WriteLine("-------------------------------------------------------------------------------")

Console.WriteLine("-------------------------------------------------------------------------------")

Console.WriteLine("-------------------------------------------------------------------------------")

Console.WriteLine("------------------------please enter a number above----------------------------")

Console.WriteLine("-------------------------------------------------------------------------------")

Console.WriteLine("-------------------------------------------------------------------------------")

End Sub

Function GetMenuChoice() As Integer

Dim menuChoice As String

Dim isvalid As Boolean

isvalid = False

menuChoice = ""

Do Until isvalid = True 'when it gets to true you are safe to proceed

DisplayMenu() 'shows the menu

menuChoice = Console.ReadLine 'saves the entered choice

isvalid = isoptionvalid(menuChoice)

Loop

Return menuChoice

End Function

Function isoptionvalid(ChoosenOption As String) As Boolean



If ChoosenOption.Length = 0 Then

Console.WriteLine("This is not valid")

Return False

End If

If InStr("123456789", ChoosenOption) < 1 Then 'checks if the number is smaller then one if it is it returns error

Console.WriteLine("This is not valid")

Return False

End If

If ChoosenOption > 2 Then 'checks if the number is bigger then two if it is it returns error

Console.WriteLine("This is too long, try again")

Return False

End If

If ChoosenOption = 2 Then 'if the entered number is two it ends the program

MsgBox("Goodbye") 'says goodbye when user enters the second option

End

End If

Return True

End Function

Sub getdecksize()

Console.WriteLine("How many cards do you want to play with? please enter an even number between 4 and 22") 'asks how many cards you want to play with

amountofcards = Console.ReadLine()

Do Until checkdecksize(amountofcards) = True

Console.WriteLine("How many cards do you want to play with? please enter an even number between 4 and 22") 'asks how many cards you want to play with

amountofcards = Console.ReadLine()

Loop

End Sub

Function checkdecksize(amountofcards As String) As Boolean

If amountofcards.Length = 0 Then

Console.WriteLine("Please try again, press space to start again!!")

Console.ReadLine()

Return False

End If

If amountofcards.Length > 2 Then

Console.WriteLine("Please try again, press space to start again!!")

Console.ReadLine()

Return False

End If

If amountofcards.Length = 1 Then

If InStr("0123456789", amountofcards) < 1 Then

Console.WriteLine("Please try again, press space to start again!!")

Console.ReadLine()

Return False

End If

End If

If amountofcards.Length = 2 Then

If InStr("0123456789", Mid(amountofcards, 1, 1)) < 1 Then

Console.WriteLine("Please try again, press space to start again!!")

Console.ReadLine()

Return False

End If

If InStr("0123456789", Mid(amountofcards, 2, 1)) < 1 Then

Console.WriteLine("Please try again, press space to start again!!")

Console.ReadLine()

Return False

End If

End If





If amountofcards < 4 Or amountofcards > 22 Then

Console.WriteLine("Please try again, press space to start again!!")

Console.ReadLine()

Return False

ElseIf amountofcards Mod 2 > 0 Then

Console.WriteLine("Please try again, press space to start again!!")

Console.ReadLine()

Return False

End If

Return True

End Function



Sub getnameoffootballers()

Dim counter As Integer = 0

FileOpen(1, "C:\FileName.txt", OpenMode.Input)

Do Until EOF(1)

ReDim Preserve cards(counter)

cards(counter).name = LineInput(1)



counter = counter + 1

Loop

FileClose(1)

End Sub

Sub dealhands(gamesize As Integer)

ReDim playershand((gamesize / 2) - 1)

ReDim computershand((gamesize / 2) - 1)

For looper = 0 To ((gamesize / 2) - 1)

Randomize()

Dim randomnumber = Int(Rnd() * cards.Length)

playershand(looper) = cards(randomnumber)

removefromdeck(randomnumber)

Randomize()

randomnumber = Int(Rnd() * cards.Length)

computershand(looper) = cards(randomnumber)

removefromdeck(randomnumber)

Next

End Sub

Sub removefromdeck(i As Integer)

For looper = i To cards.Length - 2

cards(looper) = cards(looper + 1)

Next

ReDim Preserve cards(cards.Length - 2)

End Sub

Sub setattributes()

For looper = 0 To cards.Length - 1

cards(looper).heading = Int(Rnd() * 5 + 1)

cards(looper).shooting = Int(Rnd() * 100 + 1)

cards(looper).dribbling = Int(Rnd() * 10 + 1)

cards(looper).injury = Int(Rnd() * 10 + 1)

Next

End Sub

Sub altshowtopcard()

Dim computerscatogory As Integer

computerscatogory = Int(Rnd() * 4 + 1)

Console.WriteLine("computer is choosing...")

Console.WriteLine("the computer has chosen " & computerscatogory)

Console.ReadLine()

GetTopCard("P")

Console.WriteLine("")

Console.WriteLine("")

GetTopCard("c")

If computerscatogory = 1 Then comparestats1()

If computerscatogory = 2 Then comparestats2()

If computerscatogory = 3 Then comparestats3()

If computerscatogory = 4 Then comparestats4()

End Sub

Sub GetTopCard(x As Char)

loseorwin = 0

If x = "P" Then

Console.WriteLine("Players Card")

Console.WriteLine("name: " & playershand(0).name)

Console.WriteLine("1.heading: " & playershand(0).heading)

Console.WriteLine("2.shooting: " & playershand(0).shooting)

Console.WriteLine("3.dribbling: " & playershand(0).dribbling)

Console.WriteLine("4.Injury: " & playershand(0).injury)

Else

Console.WriteLine("Computers Card")

Console.WriteLine("name: " & computershand(0).name)

Console.WriteLine("1.heading: " & computershand(0).heading)

Console.WriteLine("2.shooting: " & computershand(0).shooting)

Console.WriteLine("3.dribbling: " & computershand(0).dribbling)

Console.WriteLine("4.Injury: " & computershand(0).injury)

End If

End Sub

Function showtopcard()

Dim chosencategory As String = 0

GetTopCard("P")

Console.WriteLine("")

Console.WriteLine("please select a category to compare with the computer (1,2,3,4)")

Dim isvalid1 As Boolean

isvalid1 = False

Do Until isvalid1 = True

chosencategory = Console.ReadLine

isvalid1 = iscategoryvalid(chosencategory)

Loop

GetTopCard("c")

If chosencategory = 1 Then comparestats1()

If chosencategory = 2 Then comparestats2()

If chosencategory = 3 Then comparestats3()

If chosencategory = 4 Then comparestats4()

Return chosencategory

End Function

Function iscategoryvalid(chosencategory As String) As Boolean

If chosencategory.Length = 0 Then

Console.WriteLine("This is not valid")

Return False

End If

If InStr("123456789", chosencategory) < 1 Then

Console.WriteLine("This is not valid, please try again")

Return False

End If

If chosencategory > 4 Then

Console.WriteLine("This is too long, try again")

Return False

End If

Return True

End Function

Sub comparestats1()

If playershand(0).heading >= computershand(0).heading Then loseorwin = 1

End Sub

Sub comparestats2()

If playershand(0).shooting >= computershand(0).shooting Then loseorwin = 1

End Sub

Sub comparestats3()

If playershand(0).dribbling >= computershand(0).dribbling Then loseorwin = 1

End Sub

Sub comparestats4()

If playershand(0).injury <= computershand(0).injury Then loseorwin = 1

End Sub

Sub shiftcards()

If loseorwin = 1 Then

Console.WriteLine("")

Console.WriteLine("YOU WIN")

Console.WriteLine("")

playerwinswapcards()

Else

Console.WriteLine("")

Console.WriteLine("you LOSE")

Console.WriteLine("")

computerwinswapcards()

End If

loseorwin = 0

End Sub

Sub playerwinswapcards()

ReDim Preserve playershand(playershand.Length)

playershand(playershand.Length - 1) = playershand(0)

For looper = 0 To playershand.Length - 2

playershand(looper) = playershand(looper + 1)

Next

playershand(playershand.Length - 1) = computershand(0)

For looper = 0 To computershand.Length - 2

computershand(looper) = computershand(looper + 1)

Next

ReDim Preserve computershand(computershand.Length - 2)

stub()

End Sub

Sub computerwinswapcards()

ReDim Preserve computershand(computershand.Length)

computershand(computershand.Length - 1) = computershand(0)

For looper = 0 To computershand.Length - 2

computershand(looper) = computershand(looper + 1)

Next

computershand(computershand.Length - 1) = playershand(0)

For looper = 0 To playershand.Length - 2

playershand(looper) = playershand(looper + 1)

Next

ReDim Preserve playershand(playershand.Length - 2)

stub1()

End Sub

Sub whowins()

If playershand.Length = 0 Then

Console.WriteLine("You LOSE The GAME!")

Console.ReadLine()

whostarts = 1

Main()

End If

If computershand.Length = 0 Then

Console.WriteLine("You WIN The GAME!")

Console.ReadLine()

whostarts = 0

Main()

End If

End Sub

Sub stub()

whowins()

showtopcard()

shiftcards()

End Sub

Sub stub1()

whowins()

altshowtopcard()

shiftcards()

End Sub

End Module
Nov 9 '18 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
3135
by: deko | last post by:
Do I need to use flock() when reading a file into an array? It's possible that the file in question could be open at the time the file('filename') request is made. I realize flock() is required...
19
10274
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
4
9807
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
11
3000
by: Matt DeFoor | last post by:
I have some log files that I'm working with that look like this: 1000000000 3456 1234 1000000001 3456 1235 1000020002 3456 1223 1000203044 3456 986 etc. I'm trying to read the file...
2
1409
by: archana | last post by:
Hi all, I am new to asp.net (learning phase). I have to develop application in asp.net to read file from client pc and display statistics of that file to client. So my question is that to...
12
2838
by: SAL | last post by:
Hello, Is it possible to read a CSV from the Client, and bind my Datagrid to the data in the CSV file without uploading the file to the Server first? I have tried and in Debug mode on my...
3
2163
by: miss time | last post by:
Hi all, my java friends ^-^ I have next week quiz in reading file text ,and understand the topic very well. can any one give some question related to this topic .this help me more to...
6
16914
by: Studlyami | last post by:
Is it possible to open a file for reading, while another process has it open for writing to it? One of the problems is that the process that is writing to it is written in C and is running on a...
1
2130
Coldfire
by: Coldfire | last post by:
Hi, The strange problem i am having is, the input element of type='file' not reading file names after 20 file elements. It simple returns null on reading the 'name' of file. The code is...
1
2198
by: bjoarn | last post by:
I have an Application C# handling file reading, building index on this file, using dll wrapped with SWIG. The dll is originaly programmed in C++. Dll reports back to the the C# programm throug...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.