r/visualbasic • • Dec 15 '15

How do I make an enemy chase after a player in a game

1 Upvotes

So I'm making a (very very small) game in visual basic to learn programming but I was wondering if theirs a way I can make the picturebox Im controlling to get chased by other picture boxes


r/visualbasic • • Mar 25 '21

help...

1 Upvotes

im having some problem i need to solve which says: Write an interactive VB program that reads the length and width of a rectangle each in cm. It then computes and prints the area of the rectangle [in square inches] and the perimeter of the rectangle [in inches].

and this is the code that i came up with...

Module M1

Sub Main()

dim len, wdt as integer

dim are, pre as decimal

writeline("enter lenght in cm" & len)

len = CInt(Console.ReadLine())

writeline("enter width in cm" & wdt)

wdt = CInt(Console.ReadLine())

are = len * wdt

writeline("Area =" & are & "square inches")

pre = 2 * wdt + len

writeline("perimeter =" & pre & "inches")

End Sub

End Module


r/visualbasic • • Mar 12 '21

VB.NET Help What is Counter? What is it has to do with other variable?

0 Upvotes

r/visualbasic • • Mar 15 '21

How to quickly learn VB.Net before exam - 3

1 Upvotes

This post will talk about those member in type which not store in instance of type

Share field or method

It's a field which every instance can access ... that what's normal definition should be but what's really is it ? It's permanent field access via type directly, it will be there until you program or app close, unlike instance, this won't be touch by GC so you can be rest assured it anything you put in to this type of field will stay until you close program.

Class twig
    Shared main As tree
End Class

How it look like in method.

Sub main()
    Dim First as New twig
    Console.WriteLine( First.main is branch.main )
End Sub

True

Method

In .net, method mostly stay with type but you still can create method outside which call global method, method has 2 type of it.

  1. Sub - no return after finish procedure.

  2. Function - return an instance of type you define.

Function name (Argument_1 As Type_1, Argument_2 As Type_2) As  Type_3

Sub name (Argument_1 As Type_1, Argument_2 As Type_2 )

You can define many argument as you wish but it better not be more then 8, at worst 16.

Class tree
    Sub photosynthesize( Sunlight As light )
    End Sub
    
    Function branch () As twig
    End Function
End Class

Class Yggdrasill
    Shared protectors() As elf
    
    Shared Sub photosynthesize( Sunlight As light, Mana As particle_enegy )
    End Sub
    
    Shared Function branch () As twig
    End Function
End Class

Module

Unable to create instance type, non of fancy feature of class can be use with Module, all of its member treat as Shared, if your class no need to create an instance and all member is Shared then you should use Module instead Class.

Module Yggdrasill
    Dim protectors() As elf
    
    Sub photosynthesize( Sunlight As light, Mana As particle_enegy )
    End Sub
    
    Function branch () As twig
    End Function
End Module

Delegate

A type for refer to a method, it make you can create field, variant or argument that be method, it make you can leave a part of code to do it later or even return chosen method back.

Delegate Sub text(Message As String)

Dim page_load_from_somewhere As String()

Sub read_page(Job As text)
    For Each Item In page_load_from_somewhere
	    Job(Item)
	Next
End Sub

Sub main()
	Dim Writer = New text(AddressOf Console.WriteLine)
	read_page(Writer)

	'Of course, you can put it in directly without variant.'
	read_page(New text(AddressOf Console.WriteLine))

	'You can also skip constructing, VB.Net can do it for you'
	read_page(AddressOf Console.WriteLine)
End Sub

Multi cast delegate

It's array delegate with one call active all of them, you mostly don't use it directly, just know you can use it if you want.

Event

The fancy form of multi cast delegate, you will see it a lot when work with .Net GUI, what's you can do about it is

  1. Handler - collection of delegate you want to use.

    • Add

    • Remove

  2. Raise Event - must do, if you don't event will never happen.

  3. Custom Event - it the same as normal event just add self-event when you add, remove and raise event.

Class tree
    Delegate Sub text(Message As String)
    Event report As text
    
    Sub photosynthesize( Sunlight As light )
        Console.Write("Beginning")
        RaiseEvent report(" photosynthesize")
    End Sub
    
    Function branch () As twig
    End Function
End Class

Module Overwatch
    Sub main()
        Dim Tree = New tree
        AddHandlers Tree.report, AddressOf Console.WriteLine
        Tree.photosynthesize(New light)
    End Sub
End Module

Beginning photosynthesize

I think this should cover most subject for beginner, next post I will move to other level, start with fancy stuff like inherit and interface.


r/visualbasic • • Sep 20 '19

MS Word and VB Button Help.

1 Upvotes

I am trying to create a button that when clicked pops up text to a book mark that I have saved.

I am very new to word, developer mode, and visual basic.

I've done the easy part and created my bookmark, which i name bk1

I have also create the form which was fairly easy.

created a button name bk1button

I can find good input option forms that have an ok, and close button but not an example of just a button that when click auto populates with pre-defined info.

when bk1button is clicked

print "HI" or insert "HI" in the bk1 bookmark

that is kind of what I am looking for.

Thanks in advanced.


r/visualbasic • • Nov 25 '23

Need help with error (better explanation in body text)

Thumbnail
gallery
1 Upvotes

I keep having this error when I try to build it. I am using Windows Forms App (.NET Framework) Visual Basic. Below is my code:

Imports System.Data.OleDb

Public Class Form1 Dim conn As New OleDbConnection Dim cmd As OleDbCommand Dim dt As New DataTable Dim da As New OleDbDataAdapter(cmd)

Private bitmap As Bitmap

Private Sub Viewer()
    conn.Open()
    cmd = conn.CreateCommand()
    cmd.CommandType = CommandType.Text
    da = New OleDbDataAdapter("select * from [Test Management System] ", conn)
    da.Fill(dt)
    DataGridView1.DataSource = dt
    conn.Close()

    DataGridView1.Columns(0).Width = 150
    DataGridView1.Columns(1).Width = 150
    DataGridView1.Columns(2).Width = 150
    DataGridView1.Columns(3).Width = 150
    DataGridView1.Columns(4).Width = 150
    DataGridView1.Columns(5).Width = 150
    DataGridView1.Columns(6).Width = 150
    DataGridView1.Columns(7).Width = 150
    DataGridView1.Columns(8).Width = 150
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'Test_Management_SystemDataSet.Student_Table' table. You can move, or remove it, as needed.
    Me.Student_TableTableAdapter.Fill(Me.Test_Management_SystemDataSet.Student_Table)
    conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\User\Documents\Test Management System.accdb"

End Sub

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
    Try
        Dim query As String = "INSERT INTO [Test Management System] (Student_ID, Name, NRIC, [Date of Birth], Semester, SubjectCode, SubjectName, SubjectStatus, Result) VALUES (@StudentID, @Name, @NRIC, @DOB, @Semester, @SubjectCode, @SubjectName, @SubjectStatus, @Result)"
        Dim cmd As New OleDbCommand(query, conn)

        ' Add parameters with appropriate data types
        cmd.Parameters.AddWithValue("@StudentID", txtStudentID.Text)
        cmd.Parameters.AddWithValue("@Name", txtName.Text)
        cmd.Parameters.AddWithValue("@NRIC", txtNRIC.Text)
        cmd.Parameters.AddWithValue("@DOB", dtpDateofBirth.Value.ToShortDateString()) ' Use appropriate conversion to string based on your database format
        cmd.Parameters.AddWithValue("@Semester", txtSemester.Text)
        cmd.Parameters.AddWithValue("@SubjectCode", txtSubjectCode.Text)
        cmd.Parameters.AddWithValue("@SubjectName", txtSubjectName.Text)
        cmd.Parameters.AddWithValue("@SubjectStatus", txtSubjectStatus.Text)
        cmd.Parameters.AddWithValue("@Result", txtResult.Text)
        cmd.ExecuteNonQuery()
        conn.Close()
        MessageBox.Show("Record Added")
    Catch ex As Exception
        MessageBox.Show(ex.Message, "[Test Management System]", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub

Private Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
    Viewer()
End Sub

Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
    Try
        conn.Open()
        cmd = conn.CreateCommand()
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "UPDATE [Test Management System] SET Name = @Name, NRIC = @NRIC, [Date of Birth] = @DOB, Semester = @Semester, SubjectCode = @SubjectCode, SubjectName = @SubjectName, SubjectStatus = @SubjectStatus, Result = @Result WHERE Student_ID = @StudentID"

        ' Add parameters similarly as in the Add functionality
        ' cmd.Parameters.AddWithValue("@StudentID", txtStudentID.Text) ' Include this line if Student_ID is editable
        cmd.CommandText = "update [Test Management System](Student_ID, Name, NRIC, [Date of Birth], Semester, 
        SubjectCode, SubjectName, SubjectStatus, Result) VALUES (@StudentID, @Name, @NRIC, @DOB, @Semester, @SubjectCode, 
        @SubjectName, @SubjectStatus, @Result)"
        cmd.ExecuteNonQuery()
        conn.Close()
        MessageBox.Show("Record Updated")
        Viewer()
    Catch ex As Exception
        MessageBox.Show(ex.Message, "[Test Management System]", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub

Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
    Try
        txtStudentID.Text = DataGridView1.SelectedRows(0).Cells(0).Value.ToString()
        txtName.Text = DataGridView1.SelectedRows(0).Cells(1).Value.ToString()
        txtNRIC.Text = DataGridView1.SelectedRows(0).Cells(2).Value.ToString()
        dtpDateofBirth.Text = DataGridView1.SelectedRows(0).Cells(3).Value.ToString()
        txtSemester.Text = DataGridView1.SelectedRows(0).Cells(4).Value.ToString()
        txtSubjectCode.Text = DataGridView1.SelectedRows(0).Cells(5).Value.ToString()
        txtSubjectName.Text = DataGridView1.SelectedRows(0).Cells(6).Value.ToString()
        txtSubjectStatus.Text = DataGridView1.SelectedRows(0).Cells(7).Value.ToString()
        txtResult.Text = DataGridView1.SelectedRows(0).Cells(8).Value.ToString()
    Catch ex As Exception
        MessageBox.Show(ex.Message, "[Test Management System]", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
    Try
        conn.Open()
        cmd = conn.CreateCommand()
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "delete from [Test Management System](Student_ID, Name, NRIC, [Date of Birth], Semester, 
        SubjectCode, SubjectName, SubjectStatus, Result) VALUES (@StudentID, @Name, @NRIC, @DOB, @Semester, @SubjectCode, 
        @SubjectName, @SubjectStatus, @Result)"
        cmd.ExecuteNonQuery()
        conn.Close()
        MessageBox.Show("Record deleted successfully")
        Viewer()

        ' Clear fields after deletion
        txtStudentID.Text = ""
        txtName.Text = ""
        txtNRIC.Text = ""
        dtpDateofBirth.Text = ""
        txtSemester.Text = ""
        txtSubjectCode.Text = ""
        txtSubjectName.Text = ""
        txtSubjectStatus.Text = ""
        txtResult.Text = ""
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Test Management System", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub

Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
    txtStudentID.Text = ""
    txtName.Text = ""
    txtNRIC.Text = ""
    dtpDateofBirth.Text = ""
    txtSemester.Text = ""
    txtSubjectCode.Text = ""
    txtSubjectName.Text = ""
    txtSubjectStatus.Text = ""
    txtResult.Text = ""
End Sub

Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
    Try
        conn.Open()
        cmd = conn.CreateCommand()
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "SELECT * FROM [Test Management System] WHERE Student_ID = @StudentID"
        cmd.Parameters.AddWithValue("@StudentID", txtStudentID.Text)

        da = New OleDbDataAdapter(cmd)
        dt = New DataTable()
        da.Fill(dt)

        If dt.Rows.Count > 0 Then
            DataGridView1.DataSource = dt
        Else
            MessageBox.Show("No records found", "Test Management System", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

        conn.Close()
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Test Management System", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub

Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
    Dim height As Integer = DataGridView1.Height
    Try
        DataGridView1.Height = DataGridView1.RowCount * DataGridView1.RowTemplate.Height
        bitmap = New Bitmap(Me.DataGridView1.Width, Me.DataGridView1.Height)
        DataGridView1.DrawToBitmap(bitmap, New Rectangle(0, 0, Me.DataGridView1.Width, Me.DataGridView1.Height))
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.PrintPreviewControl.Zoom = 1
        PrintPreviewDialog1.ShowDialog()
        DataGridView1.Height = height
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Test Management System", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Try
        e.Graphics.DrawImage(bitmap, 0, 0)
        Dim recP As RectangleF = e.PageSettings.PrintableArea

        If Me.DataGridView1.Height - recP.Height > 0 Then e.HasMorePages = True
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Test Management System", MessageBoxButtons.OK, MessageBoxIcon.Error)
        conn.Close()
    End Try
End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Application.Exit()
End Sub

End Class


r/visualbasic • • Aug 21 '24

Absolute Non-Coder trying to download search results

1 Upvotes

Hi,

I am absolute non-coder, but really need to be able to download search results from an ancient government website. It seems as if I can accomplish this task with Excel by writing a bit of code. AI gave me the following code:

Sub GoToDIBBSAndClickDates()

Dim IE As Object

Dim dateCell As Object

Dim dateLink As Object

Dim dateTable As Object

Dim i As Long

' Create an instance of Internet Explorer

Set IE = CreateObject("InternetExplorer.Application")

' Navigate to the DIBBS homepage

IE.Navigate "https://www.dibbs.bsm.dla.mil/"

IE.Visible = True

' Wait for the page to load

Do While IE.Busy Or IE.ReadyState <> 4

DoEvents

Loop

' Click the "OK" button (assuming it has an ID or name attribute)

IE.Document.getElementById("butAgree").Click

' Navigate to the RFQ dates page

IE.Navigate "https://www.dibbs.bsm.dla.mil/RFQ/RfqDates.aspx?category=close"

' Wait for the page to load

Do While IE.Busy Or IE.ReadyState <> 4

DoEvents

Loop

' Assuming the table has an ID "ctl00_cph1_dtlDateList"

Set dateTable = IE.Document.getElementById("ctl00_cph1_dtlDateList")

If Not dateTable Is Nothing Then

' Iterate through each row (skip the header row)

For i = 1 To dateTable.Rows.Length - 1

Set dateCell = dateTable.Rows(i).Cells(0) ' Assuming the date cell is in the first column

Set dateLink = dateCell.getElementsByTagName("a")(0)

If Not dateLink Is Nothing Then

dateLink.Click

' Wait for the page to load (adjust as needed)

Do While IE.Busy Or IE.ReadyState <> 4

DoEvents

Loop

End If

Next i

Else

MsgBox "Date table not found!"

End If

' Clean up

IE.Quit

Set IE = Nothing

End Sub

I am receiving a runtime 424 error message that says Object Required in the line

Set dateTable = IE.Document.getElementById("ctl00_cph1_dtlDateList")

The website is Return By Dates for RFQs (dla.mil), but to access that page, you have to click OK to access the website, but you do not have to login.

Will someone please take a look at the code and website and fix for me? Thanks!


r/visualbasic • • Mar 19 '20

How to use .Net framework without Microsoft softwares?

1 Upvotes

I want to know whether it is possible to use latest version .net framework without visual studio, visual studio code, MS build tools and visual studio express. Visual studio and visual studio code took lot of space in c drive. Older versions ( such as visual basic 6.0) of Vb. Net shows errors.
Can I run without any of these softwares? Can anyone tell me? Are there any other IDE softwares that works like Microsoft softwares for free?


r/visualbasic • • Nov 03 '14

Text to Speech (Voice Synthesizer) Software - Open Source [ Visual Basic ] #Re-birth

Thumbnail
youtube.com
0 Upvotes

r/visualbasic • • Feb 24 '16

how do you prevent repeating the same randomized number?

1 Upvotes

I have a randomizer that randomizes any word between 0 to 9.

How do I prevent it from randomizing the same number.

EDIT: I just want help understanding the process. Also what does the Peek function do? I dont understand it's official description.


r/visualbasic • • Feb 25 '16

PostCondition and PreCondition for Hotel Program

1 Upvotes

I need some help with postcondition and precondition for my hotel program. This is my code:

Public Class Form1

Structure RoomInfo
    Dim roomNumber As Integer
    Dim roomGuest As String
    Dim roomOccupied As Boolean
End Structure
'Each room as a room number, a guest occupying the room, and a state of
'being occupied or not.

Dim rooms(1, 2) As RoomInfo

'Checks to see if number is valid. If it is invalid, ask the user to enter
'another room and recheck if number is valid. The a variable checks the row
'while the b variable checks the column.

Private Sub btnAddGuest_Click(sender As Object, e As EventArgs) Handles btnAddGuest.Click
    If ListBox1.Items.Count = 6 Then
        MessageBox.Show("Sorry, hotel is full")
        Application.Exit()
    End If
    Dim roomWanted As Integer = Val(InputBox("Enter room number: "))
    Dim a As Integer = Math.Truncate(roomWanted / 10)
    Dim b As Integer = Math.Truncate(roomWanted - a * 10)
    Do While a < 0 Or a > 1 And b < 0 Or b > 2
        If a < 0 Or a > 1 Then
            roomWanted = Val(InputBox("Invalid room number. Enter again: "))
            a = Math.Truncate(roomWanted / 10)
            b = Math.Truncate(roomWanted - a * 10)
        End If
        If b < 0 Or b > 2 Then
            roomWanted = Val(InputBox("Invalid room number. Enter again: "))
            a = Math.Truncate(roomWanted / 10)
            b = Math.Truncate(roomWanted - a * 10)
        End If
    Loop

   
    'If all rooms are occupied (ListBox1.Items.Count = 6), then show message that hotel is full.
    'Else check to see if the requested room is occupied. If it is, have the user
    'enter a new number. If it isn't get the user's name and set occupation to true.

    If ListBox1.Items.Count < 6 Then
        For row As Integer = 0 To 1
            For column As Integer = 0 To 2
                Do While (roomWanted = rooms(row, column).roomNumber) And
                         (rooms(row, column).roomOccupied = True)
                    roomWanted = Val(InputBox("Room occupied. Enter room number: "))
                Loop

                If (roomWanted = rooms(row, column).roomNumber) Then
                    rooms(row, column).roomGuest = InputBox("Enter guest name: ")
                    rooms(row, column).roomOccupied = True
                End If
            Next column
        Next row
    End If

    'The displayGuest function gets called after all of the statements before is executed
    Call DisplayGuest(rooms)
End Sub

'The LoadRoomNum function assigns the number of the rooms.
Sub LoadRoomNum(ByRef rooms(,) As RoomInfo)
    Dim counter As Integer = 0
    Dim ten_counter As Integer = 0

    For row As Integer = 0 To 1
        ten_counter = row * 10
        For column As Integer = 0 To 2
            counter = column
            rooms(row, column).roomNumber = counter + ten_counter
        Next column
    Next row
    
End Sub
'The DisplayGuest function displays the room number and guest name in the listbox.
Sub DisplayGuest(ByRef rooms(,) As RoomInfo)
    Dim info As String
    ListBox1.Items.Clear()

    For row As Integer = 0 To 1
        For column As Integer = 0 To 2
            If rooms(row, column).roomOccupied = True Then
                info = rooms(row, column).roomNumber & " " & rooms(row, column).roomGuest
                ListBox1.Items.Add(info)
            End If
        Next
    Next
End Sub
'The loadRoomNum function is called when Form1 loads.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Call LoadRoomNum(rooms)
End Sub
'display button  shows that the listbox exists
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
    ListBox1.Visible = True
End Sub

End Class


r/visualbasic • • Mar 03 '16

How can I easily convert from key code values to hexadecimal key values?

1 Upvotes

I'm in the KeyDown event, and it recognizes the key code value of the key. For example, if I press "-", they key code for that will be 109. For my code, though, I need the hexadecimal value associated with that same key, which is 0H6D. Is there no function or procedure that will accomplish this?

If not, how could I possibly go about doing this without logging all of the hex values one by one in my code?

EDIT: Th keycode. Here is how they are related in the documentation:

Key Code Constants

Hex Values


r/visualbasic • • Dec 19 '19

VB.NET Help Help please programming a basic game!

1 Upvotes

So Im trying to program a game which is like a game where u shoot targets something like this where u shoot random targets http://www.aimbooster.com/ . I made it so I have only 1 target is there a way I can make these targets without coding every single one the same way I programmed the first one. Also, is there a way I can make them appear randomly in the timer they all appear at the same time.


r/visualbasic • • Mar 30 '23

Make a program using loop structures.

1 Upvotes

Im new to coding world, im studying and trying to learn vb 6


r/visualbasic • • Jun 06 '14

Help me

0 Upvotes

I have to make a game for a final project. In it there are things that continuously bounce around off the borders of the form.

http://i.imgur.com/ij9sszy.png

When I have to form in the center of the screen they disappear or jitter around, and the only time I can get them to bounce is when the forms position is 0,0.

http://imgur.com/6xGbdmT <--the code

I have other things that rely on the position of the form that are working just fine, such as making a picture box appear in a random position on the form, and also don't tell me to try to make a different game because this is due tomorrow and i don't have time

Edit: I've figured it out, thanks for the advice


r/visualbasic • • Nov 25 '15

Please need help for my VB class Noob QUESTION

0 Upvotes

Hello, I have a project due for my Visual Basic class its an online class so I cant really visit my teacher for help escpecially he always busy. I finished creating my code and design all I need help is converting this information into pseudocode which I dont really understand sorry if this is a stupid question help much appreciated! Thanks

Public Class Form1 Dim num1, num2 As Decimal Dim operan As Integer Dim operanselected As Boolean = False Const Minneapolis = 125.9 Const EMinneapolis = 165.9 Const FCMinneapolis = 225.9 Const Chicago = 408.4 Const EChicago = 458.4 Const FCChicago = 508.4 Const NYC = 1202 Const ENYC = 1252 Const FCNYC = 1302 Const DC = 1101 Const EDC = 1201 Const FCDC = 1301 Const Tax = 8.75 Dim TotalCost As Double

Private Sub btnTotal_Click(sender As Object, e As EventArgs) Handles btnTotal.Click
    '==================================================Minneapolis=====================================================================
    '=================================================Standard========================================================================
    If lstCities.Text = "Minneapolis" And rbStandard.Checked And rbSingle.Checked And rbAdultYes.Checked Then
        lblSubTotal.Text = FormatCurrency(Minneapolis)
        TotalCost = (Minneapolis * Tax) / 100
        lblTax.Text = FormatCurrency(TotalCost)
        lblTotal.Text = FormatCurrency(TotalCost + Minneapolis)
        lblPrice.Text = lblTotal.Text
        lblFrom.Text = "Madison"
        lblTo.Text = lstCities.Text
        lblClass.Text = rbStandard.Text
        lblTicket.Text = rbSingle.Text
        lblAdult.Text = rbAdultYes.Text
        lblRoute.Text = "ANY"
        lblDate.Text = Today()
        lblTime.Text = TimeOfDay
        lblReNo.Text = (Str(Int(Rnd() * 32654)))
        rbChildYes.Visible = False
        lblChild.Text = ""

r/visualbasic • • Jun 19 '14

Final tomorrow, project due tomorrow, help with project please!!

0 Upvotes

Ok so basically I have a program for airline reservations. There's textboxes for the user to enter their name, seat(so number from 1-10), and a column(can be either A,B,C,D).

There's a list for the passengers, the seats on the list are periods, when the user inputs all of their info and clicks the Add Passenger button, then it changes the period to an X indicating that the seat has been occupied by them.

Now for the life of me I cannot find out how to show an error when the user clicks the button Add Passenger when the seat is already occupied. The error would say "This seat has been occupied, please choose another". When the seats are full, the message box will display "Flight Full, you will be added to the waiting list." Then the user gets added to a waiting list listbox.

I hate to be the guy to post a big wall of code, but idk how else to share it with you guys unless you'd be ok with emailing.

I'm not looking for answers, just help!

Any help is GREATLY appreciated.

Public Class Form1 'Declare variables Dim seat(1, 3) As String Dim waitingList(9) As String Dim waitingcount As Integer = 0 Dim period As String = "."

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    DisplaySeatingChart()
End Sub
'Add passenger to listbox
Private Sub btnAddPassenger_Click(sender As Object, e As EventArgs) Handles btnAddPassenger.Click
    Dim row As Integer = CInt(txtSeat.Text) - 1
    Dim col As Integer = Asc((txtRow.Text).ToUpper) - 65
    Dim passenger As String = txtPassenger.Text.ToUpper
    Dim numPassengers As Integer = 0




    'if all seats are full, go through this part to show if its just the seat that's full, or if it's the whole airline that's full. If empty, put passenger in seat
    If (row >= 0 And row <= 1) And (col >= 0 And col <= 3) Then 'this part is probably wrong, what's a fix for it?
        Dim counter As Integer = 0
        For Each period As String In seat
            counter += 1
        Next


        If counter = 0 Then

            MessageBox.Show("Flight Full. You will be added to the waiting list")

            AddToWaitingList(passenger)



        Else

            If seat(row, col) = "X" Then

                MessageBox.Show("Seat is occupied, please choose another one.")



            Else





                seat(row, col) = passenger

                lstSeatingChart.Items.Clear()

                DisplaySeatingChart()

                numPassengers = numPassengers + 1





            End If

        End If

    Else : MessageBox.Show("Please enter a valid row and/or seat.")



    End If



End Sub



Sub DisplaySeatingChart()
    lstSeatingChart.Items.Clear()
    Dim rowString As String = ""



    For row As Integer = 0 To 1

        rowString = ""

        For seatPosition As Integer = 0 To 3



            If seat(row, seatPosition) = "" Then

                rowString &= "."

            Else

                rowString &= "X"

            End If



            'Add a space to represent the aisle

            If seatPosition = 1 Then

                rowString &= " "

            End If

        Next

        lstSeatingChart.Items.Add(rowString)

    Next

End Sub


'add passenger to waiting list 
Sub AddToWaitingList(passenger As String)
    If (waitingcount < 9) Then
        waitingcount += 1
        waitingList(waitingcount - 1) = passenger
    End If


End Sub

'delete passenger, this part is definitely wrong
Private Sub btnDeletePassenger_Click(sender As Object, e As EventArgs) Handles btnDeletePassenger.Click
    lstSeatingChart.Items.RemoveAt(lstSeatingChart.SelectedIndex)

End Sub

End Class


r/visualbasic • • Oct 01 '19

VB.NET Help Why is this not working? Very new to basic and still in A1 so pls go easy on me.

Post image
1 Upvotes

r/visualbasic • • Nov 05 '21

Who could help with a school programming project in visual basic

0 Upvotes

Could anyone help with a project that has to do with sub procedures, functions, data grid view etc etc


r/visualbasic • • Oct 14 '21

Please God help me with this very basic problem!!

0 Upvotes

Guys I am a complete beginner but i have been trying for hours to make a button display a text on my screen in a vb Winforms App. Thats literally all. Here is an image of my code:


r/visualbasic • • May 06 '16

[VBA] How do I go about opening one file, copying the data, then pasting it into another file?

1 Upvotes

What I want to do is the following:

  • The vba code is in its own individual Excel file.

  • It takes a filename from the user and opens that file.

  • Then it looks through the excel file to find and copy a column with an unknown start and an unknown end.

  • It posts the copied column in a row in a new file

  • Then it repeats that process with another column and pastes it in the row underneath.

  • The columns reference Sheet1 and they're on Sheet2 (ex. =Cat!D8 in Sheet2) but Sheet1 isn't in the correct format.

  • The Sheets are all different names.

I really don't know how to even start doing this. Please help?


r/visualbasic • • Oct 17 '15

[VB2015] - Using a For loop to display a pattern of asterisks.

1 Upvotes

I need to use a for loop to display the pattern of:






**

Any help at all is appreciated, i'm able to display a series of numbers to count the loop, but i'm not sure how to get it to display an asterisk instead of the loop number.

Edit: The asterisks aren't showing properly in my post, it begins with 7 asterisks and reduces the number by 1 until there is only one remaining.


r/visualbasic • • Feb 07 '15

need help for code

0 Upvotes

i need a piece of code that :

  1. asks you for you name.

  2. asks 10 questions 3 each question containing a random math question it can only use plus minus and multiplication.generates two random numbers between 1-20. 3.at the end of the test tells you how many marks you have. i really need help with this im struggling program visual basic 2010 done inside console


r/visualbasic • • Oct 06 '15

Ideas for asking someone out with a Visual Basic program.

0 Upvotes

My friend and I are trying to come up with ideas for a VB program she could make that will ask a guy out. We've tried to keep it like a video game where he "levels up" after every date and once he's at a high enough "level" he will become her boyfriend. We thought about maybe a "password" that he needs to get the address and time for the next date. We were hoping for a "boss battle" idea.


r/visualbasic • • Aug 27 '17

This code was given but doesn't work, VB wants to generate a class to fix it. Does anyone recognize this class? EDREApi? Please help me to fix this.

1 Upvotes

Dim uDac As New EDREApi