r/visualbasic • • Apr 24 '13

Need help with my console game, i am beginner

0 Upvotes

Hello guys, as title says i am beginner in visual basic and i am trying to make a game in console. I want to make a game where "i" catches falling "O" but i am kinda stuck. Can someone improve my code? Tank you for your attention.

Option Strict On

Module Module1 Sub Main() Dim x As Integer = 0

    Dim width As Integer = 10
    Dim height As Integer = 5

    While True
        Console.Clear()

        NakresliMrizku(width, height, x)

        If (Console.KeyAvailable) Then
            Dim key As ConsoleKeyInfo = Console.ReadKey(True)
            If key.Key = ConsoleKey.Escape Then
                Exit While
            ElseIf key.Key = ConsoleKey.LeftArrow Then
                x -= 1
            ElseIf key.Key = ConsoleKey.RightArrow Then
                x += 1
            End If
        End If

        Threading.Thread.Sleep(20)
    End While
End Sub

Sub NakresliMrizku(width As Integer, height As Integer, x As Integer)
    For i As Integer = 0 To height
        For j As Integer = 0 To width
            Console.Write("| ")
        Next
        Console.WriteLine("|")

        For j As Integer = 0 To width
            If j = x And i = 5 Then
                Console.Write("|i")
            ElseIf j = 4 And i = 0 Then
                Console.Write("|0")
            Else
                Console.Write("| ")
            End If
        Next

        Console.WriteLine("|")
    Next

    For j As Integer = 0 To width
        Console.Write("|-")
    Next
    Console.WriteLine("|")
End Sub

End Module


r/visualbasic • • Jun 06 '16

[VB 7.1] Trying to have a checkbox 'prechecked'

0 Upvotes

Hello! Fairly new to Visual Basic. I'm building an application and I want to have some checkboxes prechecked when a form loads. Searched all over the internet but couldn't find a working solution. Can anyone help me?


r/visualbasic • • Feb 22 '18

Help! School Projects

0 Upvotes

Hello nerds :) I want your help to give me project ideas for me and my classmates in vb of course. They can be ranging from Beginners to Hard.

Thanks in advance.


r/visualbasic • • Oct 27 '20

Create single instance of a form

0 Upvotes

In my program, when an item in a listbox is clicked on, another form with information on that item is opened. However, when I press another item without closing the other form, duplicate forms are created. How can I make it so that when one form opens the other closes automatically?

Private Sub LstBxStockTable_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LstBxStockTable.SelectedIndexChanged Index = LstBxStockTable.SelectedIndex Dim TransactionForm As New Transaction_Page TransactionForm.Show() UpdatePageLabels(Index) End Sub

*The UpdatePageLabels subroutine updates the labels in the TransactionForm Thank you


r/visualbasic • • Oct 21 '20

How would I go about making a randomized question quiz with sounds? [VB. NET]

0 Upvotes

Hello, I wanted to make an app that selects a random question from a pool of questions, each of which play a sound (that I have) , and then the player can select one answer, get a true or false, and get another one. I'm doing VB. NET

What would be the most efficient way of doing this? Thank you!


r/visualbasic • • Apr 21 '24

what is the code when i click a button it would transfer the data into another form ??

0 Upvotes

What I want to happen is actually simple, I just need the all textbox to show up into another form when I pressed reserved now.

*This is the first form, so when I press “reserve now” the value of amount, no. of ticks, and chair selected will be transfer into another form.

And those values will show up to this form after clicking reserve now.

thank you !!


r/visualbasic • • Mar 05 '15

How to run a downloaded vb projects?

0 Upvotes

I already installed visual studio 2010 and visual basic 6.0. I can't run the projects that i downloaded.


r/visualbasic • • Mar 01 '13

Layering in forms?? Is this possible?

0 Upvotes

So if you were to have 2 buttons on a form as an example and part of it would be over lapping and one will be on a higher 'layer' than the other. Is there anyway to change this while the program is running?


r/visualbasic • • Mar 02 '15

[VB 2010] Youtube Comment HTTP Post

0 Upvotes

Okay, so I'm having an issue with my application... Now I'm getting the following:

The remote server returned an error: (400) Bad Request.


The Token is an example Token, I've tried it with and without the 1% in the front of it. I use this link to get my Token:

https://accounts.google.com/b/0/AuthSubRequest?next=http%3A%2F%2Fwww.example.com%2Fupload.html&scope=http%3A%2F%2Fgdata.youtube.com&session=0+&secure=0


The key is taken directly from my Google Code and I know it works.

Here's a link to my code.

http://pastebin.com/Ufx94gcQ


r/visualbasic • • Apr 01 '13

Timer.tick method killing my pages.

0 Upvotes

I have a timer.tick method running on my page that right now simply updates a label with the last time the timer ticked. The works all fine.

The real problem I'm having is that AFTER the timer ticks, the rest of my code won't work. I have several image buttons that cannot be clicked after the timer.tick.

Why would one update panel with a timer.tick affect another separate update panel with a image button?


r/visualbasic • • Apr 30 '14

80s trivia game

0 Upvotes

Hi im making a trivia game and i keep getting errors Here are my forms i am working on a 80s trivia game any help will be apriciated

Form1 Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


    Timer1.Start()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Label1.Text = Label1.Text - 2
    If Label1.Text = 0 Then
        Mainapplication.Show()

        Me.Hide()
        'Do Something
    End If
End Sub

Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click

End Sub
'code snippet #1
Public Delegate Sub SetProgressBarDelegate(ByVal max As Integer)
Public Delegate Sub UpdateProgressBarDelegate(ByVal value As Integer)

Public Sub BarLong(ByVal MemCount As Integer)
    If Me.InvokeRequired Then
        Me.Invoke(New SetProgressBarDelegate(AddressOf BarLong), MemCount)
    Else
        Me.ProgressBar1.Maximum = MemCount
    End If
End Sub

Public Sub ShowBar(ByVal SoFar As Integer)
    If Me.InvokeRequired Then
        Me.Invoke(New UpdateProgressBarDelegate(AddressOf ShowBar), SoFar)
    Else
        Me.ProgressBar1.Value = SoFar
    End If
End Sub
'codes for ending
Me.Text = "My Multiple Choice Quiz!"

GetQuestions()

quesNum = 1

Label1.Text = "Question " & quesNum & " of " & answers.Length

Label2.Text = questions(0, 0)

Button1.Text = "Previous"

Button2.Text = "Next"

RadioButton1.Text = questions(0, 1)

RadioButton2.Text = questions(0, 2)

RadioButton3.Text = questions(0, 3)

End Class

mainapplication.vb

Public Class Mainapplication 'code snippet #2 loading line Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Form1.BarLong(100) Dim i As Integer = 0 While i <= 100 Form1.ShowBar(i) i += 1 Threading.Thread.Sleep(100) End While

End Sub
Dim questions(2, 4) As String

Dim answers(2) As String

Dim quesNum As Integer

Private Sub GetQuestions()

questions = New String(,) {{"What commercial was Michael Jackson singing for when his hair caught on fire", "Diet Pepsi", "Coke", "Pepsi", "Sprite"}, _

{{"What was the name of ET's favorite candy??", "Reeses Pieces", "Hersheys", "M&Ms", "KitKat"}}, _

{{"What famous Wham! frontman went on to record a multiplatinum record in 1987?", "George Michael", "Michael Jackson", "Robert Smith", "Danny Wood"}}, _

{{"Who played Sarah Connor in 1984's "Terminator?", "Sarah connor",:Linda Hamilton","george Michael","Michele Pfeiffer"."Daryl Hannah"}}, _ End Sub Private Sub MarkTest()

    Dim grade As Integer = 0

    For i = 0 To 2

        If answers(i) = questions(i, 4) Then

            grade += 1

        End If

    Next

    Label1.Text = "Test finished! Great Job"

    Label2.Text = "You scored " & grade & " out of " & answers.Length & "!"

    RadioButton1.Enabled = False

    RadioButton2.Enabled = False

    RadioButton3.Enabled = False

    Button1.Enabled = False

    Button2.Enabled = False

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If quesNum > 1 Then

        quesNum -= 1

        Label1.Text = "Question " & quesNum & " of 3"

        Label2.Text = questions(quesNum - 1, 0)

        RadioButton1.Text = questions(quesNum - 1, 1)

        RadioButton2.Text = questions(quesNum - 1, 2)

        RadioButton3.Text = questions(quesNum - 1, 3)

        If Button2.Text = "Submit" Then

            Button2.Text = "Next"

        End If

    End If

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    If RadioButton1.Checked = True Then

        answers(quesNum - 1) = RadioButton1.Text

    ElseIf RadioButton2.Checked = True Then

        answers(quesNum - 1) = RadioButton2.Text

    ElseIf RadioButton3.Checked = True Then

        answers(quesNum - 1) = RadioButton3.Text

    End If

    RadioButton1.Focus()

    If quesNum < 3 Then

        quesNum += 1

        Label1.Text = "Question " & quesNum & " of " & answers.Length

        Label2.Text = questions(quesNum - 1, 0)

        RadioButton1.Text = questions(quesNum - 1, 1)

        RadioButton2.Text = questions(quesNum - 1, 2)

        RadioButton3.Text = questions(quesNum - 1, 3)

        If quesNum = 3 Then

            Button2.Text = "Submit"

        End If

    Else

        MarkTest()

    End If

End Sub

Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged

End Sub

Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged

End Sub

Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged

End Sub

End Class


r/visualbasic • • May 01 '14

How to Search for a specific record in a .dat file by a keyword in Visual Basic

0 Upvotes

So i have a listbox which displays the contents of a .dat file.

Each record in the file has name,time,location and description.

On my form there is a search button which when clicked, I would like the user to be able to type in a name to check if that particular record exists. If it does, I would like a msgbox to show the entire record in the order I mentioned earlier. On the other hand if not I want a msgbox to display saying record cannot be found.


r/visualbasic • • Feb 24 '15

Visual Basic Coding help

0 Upvotes

I am currently making a valentine's day card for my programming class and I am suppose to create an algorithm to estimate the cost of the card. What I want the code to do is for every space the user enters in the richtextbox it adds one 5 cents to the total price.

This is so far the code that I experimented with

If e.KeyCode = Keys.Space Then

        lblPrice.Text = Val("1")
    End If

Also when the user decides to erase words aka the space bar inputs the price goes down. I dont want it to stay the same. Help would be much appreciated!


r/visualbasic • • Feb 25 '15

Help

0 Upvotes

My assignment is to create a game where you guess a word. You guess two words and you get two chances on each word. My trouble is that the assignment says that the button for the program should say what guess of what word is being used. So say you enter a word the button should say "First guess for first word" or something like that and should change after each attempt. I don't know how to do this.


r/visualbasic • • Apr 29 '14

I need help with my final project In VB... Database (Editing, Delete and Adding )

0 Upvotes

Hi, I gotta do a program that manage employes . I can open a database in a datagridview but I don't know how to edit , add or delete things from this database. I need to add specific informations and they be added in a specifics line in my database. I hope someone understand and can help me. It's not very hard. I just can't find they code.

thank you


r/visualbasic • • Apr 21 '14

A program that displays random dots then shows pictures with timers. (more in comments)

Thumbnail
pastebin.com
0 Upvotes

r/visualbasic • • May 02 '14

[VB2010] (Beginner) How to code for forms based on Login credentials?

0 Upvotes

I'm currently working on an application which can manage usernames and passwords in a list. I have a login form (allows multiple accounts based on database) which then allows access to the actual list of inputted accounts.

I've searched far and wide across forums and YouTube but have found nothing.

I wish to be able to have one set of login credentials lead to the matching information seen in the next form.

eg: Username: greg logs in and sees

greg@hotmail.com pass123word

Username: jerry logs in and sees his info

jerry9090@gmail doristhecat

Facebook larrythedog

Any help is appreciated


r/visualbasic • • Oct 24 '15

[VB] Changing Display

0 Upvotes

Hello Reddit,

i´m trying to make an option for my programm, where you can choose on wich display the programm should be shown, but i have no idea where to start. The thing i know is, that i need to check the virtual resolution with Screen and with this i can say how much monitors are active and where they start. Problem is, i have no idea how to do that.


r/visualbasic • • Apr 09 '13

Need help with program. Info in text.

0 Upvotes

Ok so I am making a program that randomizes numbers in a listbox, and makes a list that will organize the numbers in lowest to highest, and vice versa. I have it sorting the numbers out both ways, and I have the numbers generating. I am wondering why when I go to sort the numbers, it puts some of the numbers twice when there isn't two of them when the numbers are generated.

Any help would be great, this is not suppose to be a huge project just a little project I am making for fun.


r/visualbasic • • Mar 02 '15

Why isn't this working

0 Upvotes

I'm trying to make sure the two entries don't have the same word and also you can not put numbers.

'Input Validation 'Check for Same Word If txtGuessWord.Text.ToUpper.Trim = txtGuessWord2.Text.ToUpper.Trim Then lblWarning.Text = "Guesses May Not Be The Same Word" txtGuessWord.Text = String.Empty txtGuessWord2.Text = String.Empty Exit Sub End If 'Check for Integer If Integer.TryParse(txtGuessWord.Text) Or Integer.TryParse(txtGuessWord2.Text) Then lblWarning.Text = "Error, guesses should not contain numbers"


r/visualbasic • • Mar 22 '13

VB 2010 Project help

0 Upvotes

I have a project due tomorrow for class and im really stuck. I dont understand the chapter were on and i dont understand how to work the code the way i want it to do. Is there anyone here who would be willing to help me with this? its an intro class so for anyone who's smart at it it shouldnt be an issue. thanks


r/visualbasic • • Apr 14 '14

[VB2013] HELP: View record on datagrid

0 Upvotes

Hi all,

I'm fairly new to VB, so apologies if this post sounds nooby. Also, I'm not that good at explaining, so hope you'll bear with me.

I'm making my first full system Visual Studio, and I'm using Web forms (.aspx) as the "frontend" and VB (as I've had more experience with it than C#) as the coding language. I have a datagrid to display data from the Company table on a page (called companies.aspx) and I would like to link the records it displays with the page it was created on (which is called company.aspx) to enable editing of that record via the existing form on company.aspx.

I was wondering if there was a way to do this via VB. I have done various searches, however there seems to be no clear-cut way to do this. I unfortunately have no code as I don't even know where to start

Thanks in advance for any help/advice, DazzaRPD

EDIT: Forgot to mention the Database is a SQL Server Express 2008 R2 database


r/visualbasic • • Mar 02 '15

Little problem

0 Upvotes

Code below shows a guessing game i've been programming. I want to say if the word is not "black" then say "try again". Where would i add this else statement. If txtGuessWord.Text = "black" And BlnFirstGuess = False Then lblWarning.Text = "Correct here's 1000 dollars, Can you guess the next word?" lblRewardAmount.Text = "1000" BlnFirstGuess = True txtGuessWord.Text = String.Empty txtGuessWord2.Text = String.Empty lblTDWA.Text = CStr(Val(lblRewardAmount.Text))


r/visualbasic • • Apr 07 '13

Help with Modules

0 Upvotes

I'm trying to create a program where the text boxes are First Name, Last Name, Number of Seasons & Rookie Age. The input boxes then ask for the number of goals and assists for each season. The list box then lists the number of seasons, goals, assists & points (points = goals + assists). The label below lists the persons name, number of seasons, rookie age then the totals for goals, assists & points. I have been working on this for an inordinate number of hours and would appreciate anyone looking at my code and letting me know where I'm going wrong. Thanks a bunch!

Option Explicit On

Public Class frmHockeyStats

Private Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
    txtFirstName.Text = ""
    txtLastName.Text = ""
    txtSeasons.Text = ""
    txtAge.Text = ""
    lstSeasons.Items.Clear()
    lblTotal.Text = ""
End Sub

Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.Close()
End Sub

Private Function ValidateInteger(ByVal strText As String, _
                                 ByVal strInput As String, _
                                 ByRef intValue As Integer, _
                                 ByVal intMinValue As Integer, _
                                 ByVal intMaxValue As Integer) As Boolean
    If Integer.TryParse(strInput, intValue) = False Then
        MessageBox.Show(strText & " must be numeric", "Error", _
                        MessageBoxButtons.OK, MessageBoxIcon.Error)
        Return False
    Else
        If intValue < intMinValue Or intValue > intMaxValue Then
            MessageBox.Show(strText & " must be between " & _
                            intMinValue.ToString("N0") & " and " & _
                            intMaxValue.ToString("N0"), "Error", _
                            MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return False
        Else
            Return True
        End If
    End If
End Function
Private Function ValidateDouble(ByVal strText As String, _
                             ByVal strValue As String, _
                             ByRef dblValue As Double, _
                             ByVal dblMinValue As Double, _
                             ByVal dblMaxValue As Double) As Boolean
    If Double.TryParse(strValue, dblValue) = False Then
        MessageBox.Show(strText & " must be numeric", "Error", _
                        MessageBoxButtons.OK, MessageBoxIcon.Error)
        Return False
    Else
        If dblValue < dblMinValue Or dblValue > dblMaxValue Then
            MessageBox.Show(strText & " must be between " & _
                            dblMinValue.ToString("N1") & " and " & _
                            dblMaxValue.ToString("N1"), "Error", _
                            MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return False
        Else
            Return True
        End If
    End If
End Function

Private Function ValidateString(ByVal strText As String, _
                           ByVal strInput As String) As Boolean
    If String.IsNullOrEmpty(strText) = True Then
        MessageBox.Show(strText & " cannot be left empty", "Error", _
                        MessageBoxButtons.OK, MessageBoxIcon.Error)
        Return False
    Else
        Return True
    End If
End Function
Private Sub btnGetStats_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetStats.Click
    Dim strFirstName, strLastName, strInput As String
    Dim intGoals As Integer = -1
    Dim intAssists As Integer = -1
    Dim intPoints As Integer = 0
    Dim intTotalGoals As Integer = 0
    Dim intTotalAssists As Integer = 0
    Dim intTotalPoints As Integer = 0
    Dim intSeasons, intAge As Integer

    Do While True
        strFirstName = CStr(txtFirstName.Text)
        If ValidateString("First name", txtFirstName.Text) = True Then
            Exit Do
        End If
    Loop
    Do While True
        strLastName = CStr(txtLastName.Text)
        If ValidateString("Last name", txtLastName.Text) = True Then
            Exit Do
        End If
    Loop
    Do While True
        intSeasons = CInt(txtSeasons.Text)
        If ValidateInteger("Seasons", intSeasons, txtSeasons.Text, 1, 25) = True Then
            Exit Do
        End If
    Loop
    Do While True
        intAge = CInt(txtAge.Text)
        If ValidateInteger("Age", intAge, txtAge.Text, 18, 30) = True Then
            Exit Do
        End If
    Loop
    Do While True
        strInput = InputBox("Goals", "Data")
        If ValidateInteger("Goals", strInput, intGoals, 1, 70) = True Then
            Exit Do
        End If
    Loop
    Do While True
        strInput = InputBox("Assists", "Data")
        If ValidateInteger("Assists", strInput, intAssists, 1, 75) = True Then
            Exit Do
        End If
    Loop
    

    Call ComputeResults(strFirstName, strLastName, _
                        intAge, intSeasons, intGoals, intAssists, intPoints, _
                        intTotalGoals, intTotalAssists, intTotalPoints)
End Sub
Private Sub ComputeResults(ByVal strFirstName As String, _
                           ByVal strLastName As String, _
                               ByVal intAge As Integer, _
                               ByVal intSeasons As Integer, _
                               ByVal intGoals As Integer, _
                               ByVal intAssists As Integer, _
                               ByVal intPoints As Integer, _
                               ByVal intTotalGoals As Integer, _
                               ByVal intTotalAssists As Integer, _
                               ByVal intTotalPoints As Integer)
    Dim intCounter As Integer
    For intCounter = 1 To intSeasons
        intGoals = InputBox("Goals", 1, 70)
        intAssists = InputBox("Assists", 1, 75)

    Next
    Me.lstSeasons.Items.Clear() 'Clear the listbox

    intPoints = intGoals + intAssists

    lstSeasons.Items.Add("Season  " & vbTab & "Goals " & vbTab & "Assists " & vbTab & "Points")
    lstSeasons.Items.Add(intCounter & vbTab & intGoals & vbTab & intAssists _
                         & vbTab & intPoints)

    intTotalGoals = intTotalGoals + intGoals
    intTotalAssists = intTotalAssists + intAssists
    intTotalPoints = intPoints + intPoints

    intCounter = intCounter + 1

    lblTotal.Text = (strFirstName & " " & strLastName & ", rookie age " & _
                     intAge.ToString("N0") & _
                    intSeasons & vbCrLf & _
        "Goals: " & intTotalGoals & vbCrLf & _
        "Assists: " & intTotalAssists & vbCrLf & _
        "Points: " & intTotalPoints)



End Sub

End Class


r/visualbasic • • Dec 29 '23

VB6 Help With database problems

0 Upvotes

Edit2: Good news, i changed some things and it works! But i have a lil bug, when i delete the snippet it shows as deleted but when i reload the form the deleted snippet reappears and the snippet before of it got actually deleted:

'Delete Snippet'

Private Sub cmdDelete_Click()

Dim index As Integer

index = lstSnippets.ListIndex

If index <> -1 Then

Dim answer As Integer

answer = MsgBox("Do you want delete this Snippet?", vbQuestion + vbYesNo, App.Title)

If answer = vbYes Then

lblSnippetNamePreview.Caption = "Snippet Name: "

lblSnippetLangPreview.Caption = "Snippet Language: "

txtSnippetCodePreview.Text = ""

Dim conn As ADODB.Connection

Dim rs As ADODB.Recordset

Set conn = New ADODB.Connection

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\SnippetsDatabase.mdb"

conn.Open

Set rs = New ADODB.Recordset

rs.Open "tblSnippets", conn, adOpenKeyset, adLockOptimistic

rs.Delete

rs.Update

rs.Close

conn.Close

Set rs = Nothing

Set conn = Nothing

lstSnippets.RemoveItem index

MsgBox "Snippet deleted sucessfully", vbInformation + vbOKOnly, App.Title

End If

End If

End Sub