473,668 Members | 2,661 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.Strea mReader
Dim ms As Integer = 60000

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Me.Size = Screen.PrimaryS creen.WorkingAr ea.Size
Me.Location = Screen.PrimaryS creen.WorkingAr ea.Location
End Sub

Private Sub Button1_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button1.Click

Button1.BackCol or = 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.DoE vents()
System.Threadin g.Thread.Sleep( ms)
Next i
Loop
End Sub
End Class
Nov 4 '18 #1
1 1683
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()

getnameoffootba llers() 'goes to the sub getnameoffootba llers()

setattributes()

dealhands(amoun tofcards) 'goes to the sub dealhands(amoun tofcards)

If whostarts = 1 Then

menu2()

Else

menu3()

End If

Console.ReadLin e()

End Sub

Sub menu2()

altshowtopcard( )

shiftcards()

End Sub

Sub menu3()

showtopcard()

shiftcards()

End Sub

Sub DisplayMenu()

Console.WriteLi ne("Menu---------------------------------------------------------------------------")

Console.WriteLi ne("1.Play game--------------------------------------------------------------------")

Console.WriteLi ne("2.Quit-------------------------------------------------------------------------")

Console.WriteLi ne("-------------------------------------------------------------------------------")

Console.WriteLi ne("-------------------------------------------------------------------------------")

Console.WriteLi ne("-------------------------------------------------------------------------------")

Console.WriteLi ne("------------------------please enter a number above----------------------------")

Console.WriteLi ne("-------------------------------------------------------------------------------")

Console.WriteLi ne("-------------------------------------------------------------------------------")

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.ReadLin e 'saves the entered choice

isvalid = isoptionvalid(m enuChoice)

Loop

Return menuChoice

End Function

Function isoptionvalid(C hoosenOption As String) As Boolean



If ChoosenOption.L ength = 0 Then

Console.WriteLi ne("This is not valid")

Return False

End If

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

Console.WriteLi ne("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.WriteLi ne("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.WriteLi ne("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.ReadLin e()

Do Until checkdecksize(a mountofcards) = True

Console.WriteLi ne("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.ReadLin e()

Loop

End Sub

Function checkdecksize(a mountofcards As String) As Boolean

If amountofcards.L ength = 0 Then

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

Console.ReadLin e()

Return False

End If

If amountofcards.L ength > 2 Then

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

Console.ReadLin e()

Return False

End If

If amountofcards.L ength = 1 Then

If InStr("01234567 89", amountofcards) < 1 Then

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

Console.ReadLin e()

Return False

End If

End If

If amountofcards.L ength = 2 Then

If InStr("01234567 89", Mid(amountofcar ds, 1, 1)) < 1 Then

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

Console.ReadLin e()

Return False

End If

If InStr("01234567 89", Mid(amountofcar ds, 2, 1)) < 1 Then

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

Console.ReadLin e()

Return False

End If

End If





If amountofcards < 4 Or amountofcards > 22 Then

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

Console.ReadLin e()

Return False

ElseIf amountofcards Mod 2 > 0 Then

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

Console.ReadLin e()

Return False

End If

Return True

End Function



Sub getnameoffootba llers()

Dim counter As Integer = 0

FileOpen(1, "C:\FileName.tx t", 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(games ize As Integer)

ReDim playershand((ga mesize / 2) - 1)

ReDim computershand(( gamesize / 2) - 1)

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

Randomize()

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

playershand(loo per) = cards(randomnum ber)

removefromdeck( randomnumber)

Randomize()

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

computershand(l ooper) = cards(randomnum ber)

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.Len gth - 2)

End Sub

Sub setattributes()

For looper = 0 To cards.Length - 1

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

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

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

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

Next

End Sub

Sub altshowtopcard( )

Dim computerscatogo ry As Integer

computerscatogo ry = Int(Rnd() * 4 + 1)

Console.WriteLi ne("computer is choosing...")

Console.WriteLi ne("the computer has chosen " & computerscatogo ry)

Console.ReadLin e()

GetTopCard("P")

Console.WriteLi ne("")

Console.WriteLi ne("")

GetTopCard("c")

If computerscatogo ry = 1 Then comparestats1()

If computerscatogo ry = 2 Then comparestats2()

If computerscatogo ry = 3 Then comparestats3()

If computerscatogo ry = 4 Then comparestats4()

End Sub

Sub GetTopCard(x As Char)

loseorwin = 0

If x = "P" Then

Console.WriteLi ne("Players Card")

Console.WriteLi ne("name: " & playershand(0). name)

Console.WriteLi ne("1.heading: " & playershand(0). heading)

Console.WriteLi ne("2.shooting : " & playershand(0). shooting)

Console.WriteLi ne("3.dribbling : " & playershand(0). dribbling)

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

Else

Console.WriteLi ne("Computers Card")

Console.WriteLi ne("name: " & computershand(0 ).name)

Console.WriteLi ne("1.heading: " & computershand(0 ).heading)

Console.WriteLi ne("2.shooting : " & computershand(0 ).shooting)

Console.WriteLi ne("3.dribbling : " & computershand(0 ).dribbling)

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

End If

End Sub

Function showtopcard()

Dim chosencategory As String = 0

GetTopCard("P")

Console.WriteLi ne("")

Console.WriteLi ne("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.ReadLin e

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.WriteLi ne("This is not valid")

Return False

End If

If InStr("12345678 9", chosencategory) < 1 Then

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

Return False

End If

If chosencategory > 4 Then

Console.WriteLi ne("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.WriteLi ne("")

Console.WriteLi ne("YOU WIN")

Console.WriteLi ne("")

playerwinswapca rds()

Else

Console.WriteLi ne("")

Console.WriteLi ne("you LOSE")

Console.WriteLi ne("")

computerwinswap cards()

End If

loseorwin = 0

End Sub

Sub playerwinswapca rds()

ReDim Preserve playershand(pla yershand.Length )

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

For looper = 0 To playershand.Len gth - 2

playershand(loo per) = playershand(loo per + 1)

Next

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

For looper = 0 To computershand.L ength - 2

computershand(l ooper) = computershand(l ooper + 1)

Next

ReDim Preserve computershand(c omputershand.Le ngth - 2)

stub()

End Sub

Sub computerwinswap cards()

ReDim Preserve computershand(c omputershand.Le ngth)

computershand(c omputershand.Le ngth - 1) = computershand(0 )

For looper = 0 To computershand.L ength - 2

computershand(l ooper) = computershand(l ooper + 1)

Next

computershand(c omputershand.Le ngth - 1) = playershand(0)

For looper = 0 To playershand.Len gth - 2

playershand(loo per) = playershand(loo per + 1)

Next

ReDim Preserve playershand(pla yershand.Length - 2)

stub1()

End Sub

Sub whowins()

If playershand.Len gth = 0 Then

Console.WriteLi ne("You LOSE The GAME!")

Console.ReadLin e()

whostarts = 1

Main()

End If

If computershand.L ength = 0 Then

Console.WriteLi ne("You WIN The GAME!")

Console.ReadLin e()

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
3161
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 when opening a file with fopen() when there is contention for the file: $fp=fopen($ctr, 'w'); //only write if we can get lock on file if (flock($fp, LOCK_EX)) { fwrite($fp, "0");
19
10308
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 text is available until I have read it... which seems to imply that multiple reads of the input stream will be inevitable. Now I can correctly find the number of characters available by: |
4
9824
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 = tmpfile(); /* write into tmpFile */ ...
11
3054
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 backwards and just look at the first column. Here's what I've got so far:
2
1426
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 read file from client pc do i need to upload that file on server and then start reading that file. Or is there any other alternative for this.
12
2887
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 workstation it works fine, but when I publish the page on our DEV server it doesn't fine the CSV file from the client. Has anyone done this before? If so, how do I do it? I'm new to ASP.net so
3
2176
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 understand thanks a lot and sorry for inconvenience..
6
16971
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 vxworks OS. I'm reading the file using MFC on a windows XP PC. The file is stored on a Windows 2000 server. I tried using CStdioFile.Open using the CFile::modeRead flag. When did this i received a CFileException with the cause stating...
1
2137
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 simple and has no error as I am testing it standalone
1
2219
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 callback/delegates. Among others, it reports index building(%). One callback function can receive (stop order) to stop reading file/building index. How ever i do not know how to keep the stopbutton activ while this file reading is going on. I have...
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8381
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8797
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8656
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5681
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.