Module Program
Dim startx As Integer
Dim starty As Integer
Dim endx As Integer
Dim endy As Integer
Dim maze As String(,) = {
{"x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x"},
{"O ", " ", " ", " ", " ", " ", " ", " ", " ", "x"},
{"x ", "x ", "x ", "x ", "x ", " ", "x ", "x ", " ", "x"},
{"x ", "x ", " ", "x ", "x ", " ", "x ", "x ", " ", "x"},
{"x ", "x ", " ", " ", " ", " ", "x ", "x ", " ", "x"},
{"x ", "x ", "x ", "x ", "x ", " ", "x ", "x ", "x ", "x"},
{"x ", " ", " ", " ", " ", " ", " ", " ", " ", "x"},
{"x ", " ", "x ", "x ", "x ", "x ", "x ", "x ", " ", "x"},
{"x ", " ", " ", " ", " ", "x ", "x ", "x ", " ", " "},
{"x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x"}}
Sub Main(args As String())
Console.WriteLine("This is a maze game")
Console.WriteLine("Please enter where you want to go (x and y cordinate)")
start
displaychessboard()
End Sub
Sub displaychessboard()
Console.WriteLine(" 0 1 2 3 4 5 6 7 8 9")
For x As Integer = 0 To 9
Console.Write(x & " ")
For y As Integer = 0 To 9
Console.Write(maze(x, y))
Next
Console.WriteLine()
Next
End Sub
Sub makemove()
End Sub
End Module
How do I move the position of the player based on user input.
You store the position of a player in one or more variables. Since you have a two-dimensional maze, you can use a two-element tuple or, for simplicity, a player_x and a player_y variable.
When the user provides input, you modify the variables accordingly. For example, "moving left" would decrease player_x by one.
When drawing your maze, you look at the current values of player_x and player_y. If they match the current position in your loop, you output "O" instead of a space.
Pls answer in vb
The Stack Overflow community will gladly help you understand concepts and teach you how to improve your Visual Basic skills, but we are not a "here is my task, you write code" service.
I have a class that currently works like this.
Class Maze
Public board(10, 10) As Object
Dim maze1 As New Maze With {.board = {{" ", " ", "X", "X", " ", "X", "X", "X", " ", "X"},
{"X", " ", " ", " ", " ", "X", " ", " ", " ", "X"},
{" ", " ", "X", " ", "X", " ", " ", " ", " ", "X"},
{"X", " ", "X", " ", " ", "X", "X", "X", " ", " "},
{"X", " ", "X", "X", " ", " ", " ", " ", "X", " "},
{" ", "X", " ", " ", "X", " ", " ", "X", " ", " "},
{" ", "X", "X", " ", "X", " ", " ", " ", " ", "X"},
{" ", " ", " ", " ", " ", "X", "X", " ", " ", "X"},
{"X", "X", " ", "X", " ", " ", " ", "X", " ", " "},
{" ", " ", " ", "X", "X", " ", " ", " ", "X", " "}}}
However I cant find away to remove the prespecified length without methods such as GetLength now not working.
In the .Net world, if you define a type as Object you're almost always doing something very wrong you will soon come to regret. In this case, it looks like String may be more appropriate. However, perhaps based on how this is used later it might turn out that Integer or a specific class type could be better, alongside a special method to translate this into text or graphics for output.
Moving on to the specific issue of size... consider a List:
Class Maze
Dim board As List(Of List(Of String))
board = New List(Of List(Of string)) From {
New List(Of String) From {" ", " ", "X", "X", " ", "X", "X", "X", " ", "X"},
New List(Of String) From {"X", " ", " ", " ", " ", "X", " ", " ", " ", "X"},
New List(Of String) From {" ", " ", "X", " ", "X", " ", " ", " ", " ", "X"},
New List(Of String) From {"X", " ", "X", " ", " ", "X", "X", "X", " ", " "},
New List(Of String) From {"X", " ", "X", "X", " ", " ", " ", " ", "X", " "},
New List(Of String) From {" ", "X", " ", " ", "X", " ", " ", "X", " ", " "},
New List(Of String) From {" ", "X", "X", " ", "X", " ", " ", " ", " ", "X"},
New List(Of String) From {" ", " ", " ", " ", " ", "X", "X", " ", " ", "X"},
New List(Of String) From {"X", "X", " ", "X", " ", " ", " ", "X", " ", " "},
New List(Of String) From {" ", " ", " ", "X", "X", " ", " ", " ", "X", " "}
}
Now you can add a line to end like so:
board.Add(New List(Of String) From {" ", "X", " ", " ", " " ... })
Or add a column like this:
For Each c As List(Of String) In board
c.Add(" ")
Next
This allows you to have 2d array without specifying length explicitly
Public board(,) As Object = {}
Actually i'm formatting data to insert in my MySQL DB and i'm at the point where i'm managing the NULL values.
So for manage it i've set a try catch inside the if where i look for datatype and now i have to put in the Catch exception the default value of certain type.
But how can i do it in VB.NET?
Here is my code, any suggestion for code improvment will be grateful
For Each row As DataRow In ds.Tables(0).Rows
righe = ""
For Each column As DataColumn In ds.Tables(0).Columns
If column.DataType = Type.GetType("System.DateTime") Then
Try
righe &= "'" & Format(row.Item(column.ColumnName), "yyyy-MM-dd") & "', "
Catch ex As Exception
End Try
ElseIf column.DataType = Type.GetType("System.TimeSpan") Then
righe &= "'" & Format(row.Item(column.ColumnName).ToString, "HH\:mm\:ss") & "', "
ElseIf column.DataType = Type.GetType("System.Int32") Then
righe &= row.Item(column.ColumnName) & ", "
ElseIf column.DataType = Type.GetType("System.Single") Then
righe &= Replace(row.Item(column.ColumnName), ",", ".") & ", "
ElseIf column.DataType = Type.GetType("System.Byte") Then
righe &= row.Item(column.ColumnName) & ", "
ElseIf column.DataType = Type.GetType("System.Double") Then
righe &= Replace(row.Item(column.ColumnName), ",", ".") & ", "
ElseIf column.DataType = Type.GetType("System.String") Then
righe &= "'" & APICI(row.Item(column.ColumnName)) & "', "
End If
Next
righe = Mid(righe, 1, Len(righe) - 2)
Next
here is my code to submit data to my csv file. How do I check to see if the data already exists before saving it.
Dim csvFile As String = My.Application.Info.DirectoryPath & "\HoseData.csv"
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, True)
'If My.Computer.FileSystem.FileExists(csvFile) Then
'outFile.WriteLine("job number, sales order number, date, requested by, serial number, hose type, hose size, fitting 1, fitting 2, qty, oal, cut off, offset, crimp 1, crimp 2, cleaned, pigged", False)
'End If
outFile.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & """" & DateTimePicker1.Text & """" & "," & ComboBox1.Text & "," & TextBox3.Text & "," & ListBox2.Text & "," & ListBox3.Text & "," & TextBox11.Text & "," & TextBox12.Text & "," & NumericUpDown1.TextAlign & "," & TextBox4.Text & "," & TextBox5.Text & "," & TextBox6.Text & "," & TextBox9.Text & "," & TextBox10.Text & "," & ListBox4.Text & "," & ListBox5.Text)
MessageBox.Show("INPUT WAS SAVED")
Dim butt As System.Windows.Forms.Button = DirectCast(sender, System.Windows.Forms.Button)
butt.Enabled = False
'butt.Visible = False
outFile.Close()
Console.WriteLine(My.Computer.FileSystem.ReadAllText(csvFile))
Is this what you're looking for?
Dim fn As String = My.Application.Info.DirectoryPath & "\HoseData.csv"
Dim fileText As String
Dim outString As String = TextBox1.Text & "," & TextBox2.Text & "," & """" & DateTimePicker1.Text & """" & "," & ComboBox1.Text & "," & TextBox3.Text & "," & ListBox2.Text & "," & ListBox3.Text & "," & TextBox11.Text & "," & TextBox12.Text & "," & NumericUpDown1.TextAlign & "," & TextBox4.Text & "," & TextBox5.Text & "," & TextBox6.Text & "," & TextBox9.Text & "," & TextBox10.Text & "," & ListBox4.Text & "," & ListBox5.Text
Using reader As StreamReader = File.OpenText(fn)
fileText = reader.ReadToEnd
End Using
Using outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(fn, True)
If fileText.Contains(outString) Then
'do stuff when the string is already present, e.g.:
MessageBox.Show("You've already entered that one.")
Else
'do stuff when it isn't, e.g.:
outFile.WriteLine(outString)
End If
End Using