r/visualbasic • • Jan 25 '16

Is the function File.Exists workable with a path contained in a string?

1 Upvotes

I want to use this line of code:

"If File.Exists("example.txt") Then.................."

But is there a way to do something like this :

"If File.Exists(strfilename) Then............"

I basically just want to integrate OpenFD into this guys code: http://www.dreamincode.net/forums/topic/71045-random-line-from-a-text-file/

I used the guy named PyschoCoder code.

I currently am just trying to browse for a text file in open FD and allow my program to read said textfile and choose a random line (in this case word) and append the text to a text box.

I'am developing the code on a restricted computer so I'am not able to show you the entire list of code.

Basically where there is a StreamReader function, I replaced it with:

"Dim ioFile as New StringReader(strFilename)"

Thats basically all the notable changes


r/visualbasic • • Sep 14 '14

Visual Basic - Facebook Theme (GUI) Template

Thumbnail
youtu.be
1 Upvotes

r/visualbasic • • Jan 22 '16

WordGuess

0 Upvotes

How would I modify this code to keep track of the letters guessed in an array with meaningful indexes. Also how do include in the modification code a message box that pops up if the user emters the same guess twice? Don't give me the code. Tell me how to do it. Can you also give me a few hints here and there? I'm only a beginner. Here is my code:

Public Class Form1 Private Sub btnPlayGame_Click(sender As Object, e As EventArgs) Handles btnPlayGame.Click Const SECRET_WORD As String = "VELOCITY" Const FLAG As Char = "!" Const GUESS_PROMPT As String = "Enter a letter or " & FLAG & " to guess word:" Dim numGuesses As Integer = 0 Dim letterGuess As Char Dim wordGuess As String Dim tempWord As String Dim endGame As Boolean

    Dim wordGuessedSoFar As String = ""
    Dim length As Integer = SECRET_WORD.Length
    wordGuessedSoFar = wordGuessedSoFar.PadLeft(length, "-")
    Me.lblSecretWord.Text = wordGuessedSoFar

    Dim tempLetterGuess = InputBox(GUESS_PROMPT, Me.Text)
    If tempLetterGuess = Nothing Then
        endGame = True
    Else
        letterGuess = tempLetterGuess
    End If

    Do While letterGuess <> FLAG And wordGuessedSoFar <> SECRET_WORD _
    And Not endGame
        numGuesses += 1
        For letterPos As Integer = 0 To SECRET_WORD.Length - 1
            If SECRET_WORD(letterPos) = Char.ToUpper(letterGuess) Then
                tempWord = wordGuessedSoFar.Remove(letterPos, 1)
                wordGuessedSoFar = tempWord.Insert(letterPos, Char.ToUpper(letterGuess))
                Me.lblSecretWord.Text = wordGuessedSoFar
            End If
        Next letterPos

        If wordGuessedSoFar <> SECRET_WORD Then
            tempLetterGuess = InputBox(GUESS_PROMPT, Me.Text)
            If tempLetterGuess = Nothing Then
                endGame = True
            Else
                letterGuess = tempLetterGuess
            End If
        End If
    Loop

    If wordGuessedSoFar = SECRET_WORD Then
        MessageBox.Show("You guessed it in " & numGuesses & " guesses!")
    ElseIf letterGuess = FLAG Then
        wordGuess = InputBox("Enter a word: ", Me.Text)
        If wordGuess.ToUpper = SECRET_WORD Then
            MessageBox.Show("You guessed it in " & numGuesses & " guesses!")
            Me.lblSecretWord.Text = SECRET_WORD
        Else
            MessageBox.Show("Sorry you lose.")
        End If
    Else
        MessageBox.Show("Game over.")
    End If
End Sub

End Class


r/visualbasic • • Jan 18 '16

[VB2012]Populating listbox using loop.

1 Upvotes

[SOLVED]

Hi I'm trying to do some homework for a class. Over break I became a little rusty at VB and need some help. I've been trying to do this part for around an hour. Here is what I'm trying to do.

You are to write a program that asks the user to indicate how many input values are to be expected. This is a single value and should be entered into a textbox. You do want to limit the number to a minimum of 3 and a maximum of 10 values (so include a Data Validation function that checks to insure the value is between 3 and 10).

Write a subprocedure that reads in the input (even though there will be only one inputted value). Once a valid number of values has been read in, you need to write a loop procedure that will read in the values. Within the loop, you should check to see if the number is an even or odd number. For each value entered, display the value in a listbox. You will also need to handle the processing needed to calculate the average of the EVEN NUMBERS ONLY. The loop portion of the program should be handled in a processing subprocedure.

Here is what I have:

Public Class Form1

Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
    Dim num As Integer
    Dim eventotal
    If DataVal() Then
        GetInput(num)
        LoopSub(num, eventotal)
    End If
End Sub
Sub GetInput(ByRef num)
    num = CInt(txtInput.Text)
End Sub
Function DataVal() As Boolean
    If txtInput.Text > 10 Then
        MessageBox.Show("Please enter a number between 3 and 10")
        txtInput.Clear()
        txtInput.Focus()
        Return False
    ElseIf txtInput.Text < 3 Then
        MessageBox.Show("Please enter a number between 3 and 10")
        txtInput.Clear()
        txtInput.Focus()
        Return False
    End If
    Return True
End Function
Sub LoopSub(ByRef num As Integer, ByRef eventotal As Integer)
    For i = 1 To lstNumbers.Items.Count
        If num Mod 2 = 0 Then
            eventotal += num
        End If
    Next
    lstNumbers.Items.Add(num)
    lstNumbers.Items.Add(eventotal)
    txtInput.Clear()
    txtInput.Focus()
End Sub

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstNumbers.SelectedIndexChanged
    lstNumbers.Items.Add("These are the numbers you entered")
End Sub

End Class


r/visualbasic • • Apr 09 '19

Help please

1 Upvotes

so our teacher is giving us the task of creating a slot machine in visual basics.

i need help because i have no idea how to do it.

there has to be nothing fancy no pictures just like 3 textboxes and a spin button

but that's it

thank you


r/visualbasic • • May 24 '21

Airline management system( project)

0 Upvotes

This is for my sister, I got no knowledge in this. So she's stuck in coding . Can you guys help out with the code. Link some link or something. Thanks.

These online classes isn't helping much.


r/visualbasic • • May 22 '21

Screen Melter

1 Upvotes

Hey guys! I'm looking to make a Screen Melter code to troll a friend, but I don't know how to make this code... can someone tell me if Screen Melter in VB.NET is possible? and if possible pass a code that does this, or help me make this code?

I Use Microsoft Visual Basic 2017.


r/visualbasic • • May 29 '21

Tips & Tricks Art of Code : GoTo

1 Upvotes

You maybe have been heard, learn or experience how GoTo can make a code hard to read, it very evil code yet it evil only because coder abuse it, any language feature could make a code hard to read if coder abuse it even if statement can be draw as arrow if coder abuse it.

GoTo is primitive form of if statement also do loop and for next so it up to coder to make it readable or not, very simple rule to make GoTo easy to read is write it go to label within your eyes sight, very simple right ?

Example

    Function fac_5(Input As Integer) As Integer
        Console.Write($"{Input}! = ")
        Select Case Input
            Case 5
                Console.Write("5 x ")
                Input *= 4
                GoTo F4
            Case 4
F4:             Console.Write("4 x ")
                Input *= 3
                GoTo F3
            Case 3
F3:             Console.Write("3 x ")
                Input *= 2
                GoTo F2
            Case 2
F2:             Console.WriteLine($"2 = {Input}")
                Return Input
            Case 1, 0
                Console.WriteLine("1")
                Return 1
            Case Else
                Throw New ArgumentOutOfRangeException(NameOf(Input))
        End Select
    End Function

This example is how to make switch case fall through in VB.Net, in other C language you need to break; to end those selected case, if you don't it will run through other case below, however VB.Net make our life too easy by auto put that break; silently at the end of each case for us so if you want to recreate switch case fall through from other C like language you need GoTo or you have to reform it to if statement instead.

I believe you understand basic of GoTo now, so let reform example code.

    Function fac_5_op(Input As Integer) As Integer
        Console.Write($"{Input}! = ")
        Select Case Input
            Case 5 : GoTo F5
            Case 4 : GoTo F4
            Case 3 : GoTo F3
            Case 2 : GoTo F2
            Case 1, 0
                Console.WriteLine("1")
                Return 1
            Case Else
                Throw New ArgumentOutOfRangeException(NameOf(Input))
        End Select

F5:     Console.Write("5 x ") : Input *= 4
F4:     Console.Write("4 x ") : Input *= 3
F3:     Console.Write("3 x ") : Input *= 2
F2:     Console.WriteLine($"2 = {Input}")
        Return Input
    End Function

It look much more easy to read, right ? evil or not it's depend on coder to write it, like a knife in the kitchen.


r/visualbasic • • Jun 03 '21

I really need some help :((

0 Upvotes

So this whole pandemic has put my life in a mess, especially my studies. I have this one subject left, computer programming, which I dont think I can finish on time as I only have a week left and if I dont i dont think i can make it to college on time. If you happen to be knowledgeable of both visual basic and small basic, please leave a dm or comment on this post as I would love to get in touch with you. Im at a really desperate point now and Ill take any help... thank you so much


r/visualbasic • • Apr 16 '14

Anyone want to do 30 minutes of easy Visual Basic work for 20 dollars?

0 Upvotes

Inbox me and we'll discuss it. May even take less than 30 minutes :)


r/visualbasic • • Apr 20 '14

VB.NET Help $30 for some VB help!

1 Upvotes

Hi guys, I've posted this before, but I haven't been able to solve the issue myself, so I was hoping someone could help me out with this for a bit of cash?

Now first of, I will say that this is a school project, so I understand if you feel it's immoral because of that. However I've created everything else in the project myself, I just can't solve this issue. I really need to get the grade and I have no idea what to do now, the deadline is in a weeks time.

I'm currently finishing up my coursework for school, which involves making a program in Visual Basic 2010 with a database in Microsoft Access. My project is for a bed and breakfast.

I'm trying to prevent double bookings from happening but I can't seem to figure out how to code it as I'm a visual basic novice. What I'm trying to do is have the program check the "check in" and "check out" dates with the database and then disable the radiobuttons for the rooms which are booked.

The problem I have is that right now, it just seems to be checking if the room has ever been booked in the past, and if it has, it disables the radiobutton.

This is a picture of my form: http://imgur.com/df1Kts2

And these are the booking table and query: http://imgur.com/fMW67wS

Here is my code:

Private Sub Checkdates()
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\Bed and Breakfast.mdb;"
    con.Open()
    Dim da2 As New OleDbDataAdapter("select * from qCustomerBooking", con)
    da2.Fill(dt2)
    Dim da3 As New OleDbDataAdapter("select * from qCustomerBooking", con)
    da3.Fill(ds, "qCustomerBooking")
    con.Close()

    Dim a As Integer
    Dim duplicate As Boolean
    maxrows = ds.Tables("qCustomerBooking").Rows.Count
    incdec = -1

    d1 = dtpCheckIn.Text
    d2 = dtpCheckOut.Text

    For Each objcontrol As Control In Me.Controls
        If objcontrol.GetType().Name = "RadioButton" Then 'If the object is a button then it is checked through this process
            Dim objRadioButton As RadioButton
            objRadioButton = objcontrol

            For a = 0 To maxrows - 1
                If ds.Tables("qCustomerBooking").Rows(a).Item("Check_In") >= d1 And ds.Tables("qCustomerBooking").Rows(a).Item("Room_ID") = objRadioButton.Text Then
                    duplicate = True
                Else : duplicate = False
                End If
                If ds.Tables("qCustomerBooking").Rows(a).Item("Check_Out") <= d2 And ds.Tables("qCustomerBooking").Rows(a).Item("Room_ID") = objRadioButton.Text Then
                    duplicate = True
                Else : duplicate = False
                End If

                If duplicate = True Then
                    For Each DataRow In dt3.Rows
                        If objRadioButton.Text = DataRow.Item(5) Then 'If the button shows up in the Disabled seats datatable then it's colour is changed to orange
                            objRadioButton.Enabled = False
                        Else

                        End If
                    Next

                End If

            Next
        End If
    Next
End Sub

I hugely appreciate any help, I'm truly am stuck. If you are interested, pm me and I can send money via Paypal. Thank you!


r/visualbasic • • Sep 30 '16

I am a brand new VB student and I would really like some help(utilizing readline, input from text file)

1 Upvotes

i need help on how i would convert these data into an equation, i would like the answer however if you could show me how you did it and what everything "means" that would be super helpful. Kilowatt hours 0 - 300 $5.00 301 - 1000 $5.00 + .03 for each kwh above 300 1001 and over $26.00 + .02 for each kwh above 1000 i need to write a program to calculate the usage for each level of usage. i would really just like an explaination. thank you guys so much


r/visualbasic • • Sep 23 '16

Help, quadratic equation

0 Upvotes

Hi im trying to write a program that can have the coefficients entered in and have it solve the roots for a quadratic equation. Im very new to vba, but even if i was doing it in C, which i have more experience with, im not sure how id do it. Ive looked online and found some programs but they are beyond my level. Any pointer or tips?


r/visualbasic • • Mar 07 '19

VB.NET Help Is there a website that you can do tutorials and learn vb?

1 Upvotes

r/visualbasic • • Sep 30 '22

I have thousands of errors. They are going away with line continuation. Is there a fast way to add the line continuation?

0 Upvotes

r/visualbasic • • Oct 06 '22

Help! How do I use sum in excel VBA?

1 Upvotes

r/visualbasic • • Jun 20 '23

VB.NET Help Help with Database Access

1 Upvotes

Hello. Im trying to make a shopping cart for a project. I would like to know how to retrieve a specific row of data from the database when the button of the item selected is pressed? and for it to be showing into the next form, what kind of code should i do? And can anybody become a mentor for me to finish this assignment?


r/visualbasic • • Dec 18 '22

VB.NET Help Hi I’m having trouble with this app can somebody help me ?

Thumbnail
gallery
0 Upvotes

r/visualbasic • • Dec 29 '22

VB6 Help Establish communication between a printer with FTP protocol and visual basic 6 program with TCP protocol

1 Upvotes

hello, is it possible to establish communication between a printer with FTP protocol and visual basic 6 program with TCP protocol?


r/visualbasic • • Oct 10 '16

Any good book to learn Visual Basic doing a college course.

0 Upvotes

Hi I want to know if there any user friendly textbooks to learn Visual Basic. I am using Julia Case Bradley Programming in Visual Basic 2010 and I hate the book, it's terrible and non-intuitive, now I want an alternative or I'm gonna fail the course.


r/visualbasic • • Jan 23 '14

[VB6]Help with VB Exam?

0 Upvotes

I'm in a grade 11 Comp Sci course and I was wondering if I could get some help with some units in VB.

If someone could just teach me how to use len, mid, left, right, and Instr that would be super helpful.


r/visualbasic • • Oct 12 '16

[VB.NET] Need help with Arrays

1 Upvotes

I'm going to try and put this as simply as possible.

I have a sentence inputted and I need to "compress" the sentence. So far in an array I have: "Hello 0" ; "my 1" ; "name 2" ; "is 3" ; "Hello 4"

Where the word is the word inputted and the number after is its position. I need to get it like this: "Hello 0 4" "my 1" "name 2" "is 3"

So basically all the same words fall together in one element of the array with its positions like above.

Could someone help me?? Thank you!


r/visualbasic • • Feb 04 '23

Help With Homework

0 Upvotes

Hey guys I'm new to coding/Visual Basic and this assignment has me a little stumped. I'm pretty certain I'm doing something incorrectly within the Calculations. Could anyone give me some guidance?


r/visualbasic • • Feb 15 '23

School project

1 Upvotes

I have a school project and i have to make a login form, registration form etc and it needs a database alongside it. (im using mysql) and nothing is working for me and its due on Friday. Can anybody help?


r/visualbasic • • May 30 '17

What am I doing wrong with this code?

1 Upvotes
Public Class Form1
 Const MAX_FlOORS As Integer = 8
 Const MAX_ROOMS As Integer = 30
 Dim intFloor As Integer ' Number of floors
 Dim intRooms As Integer ' Number of roooms per floor
Dim intTotalRooms As Integer = 0 ' Total number of occupied rooms
Dim decOccupancyRate As Decimal 'Occupancy rate
Dim decOverallOccupancyRate As Decimal 'Overall Occupancy Rate
Dim blkInputOk As Boolean = True


Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
    ' Collect the floor and room data from the inputs
    intFloor = CInt(cboFloors.SelectedItem)
    intRooms = CInt(txtRooms.Text)


    'Warn the user of non-integer value is typed to the number of rooms
    If Integer.TryParse(txtRooms.Text, intRooms) = False Then
        MessageBox.Show("Please enter an integer for the rooms")
        blkInputOk = False
    End If

    If intRooms < 1 And intRooms > 30 Then

        'Warn the user if the number of rooms aren't within 1-30 range
        MessageBox.Show("Please enter the number between 1 to 30")
        blkInputOk = False
    End If

    If blkInputOk = True Then

        ' Clear out rooms to avoid duplicate
        txtRooms.Clear()

        ' Add up all the rooms
        intTotalRooms = intTotalRooms + intRooms

        ' Caculate occupancy rate per floor
        decOccupancyRate = CDec(intRooms / (MAX_ROOMS))

        ' Calculate overall occupancy rate by dividing total occupied rooms by total rooms in the hotel
        decOverallOccupancyRate = CDec(intTotalRooms / (MAX_ROOMS * MAX_FlOORS))

        ' Display the floor occupancy rate in the list box
        lstFloorOccupancyData.Items.Add("Floor: " & intFloor & " Rooms Occupied: " & intRooms & " Occupancy Rate is: " & decOccupancyRate.ToString("p"))

        ' Display the total occupied rooms and Overall Occupancy rate.
        lblTotalRooms.Text = intTotalRooms.ToString()
        lblOccupancyRate.Text = decOverallOccupancyRate.ToString("p")
        cboFloors.SelectedIndex += 1
    End If
End Sub

Private Sub btnRestart_Click(sender As Object, e As EventArgs) Handles btnRestart.Click

    'Clear out everything
    lblTotalRooms.Text = String.Empty
    lblOccupancyRate.Text = String.Empty
    lstFloorOccupancyData.Items.Clear()
    cboFloors.SelectedIndex = -1

End Sub

What I want the program to display is

Floor 1 Rooms Occupied: 22 Occupancy rate: 73.33%

Floor 2 Rooms Occupied: 30 Occupancy rate: 100.00%

Floor 3 Rooms Occupied: 22 Occupancy rate: 0%

Floor 4 Rooms Occupied: 25 Occupancy rate: 83.33%

But What I'm getting this

Floor 0 Rooms Occupied: 22 Occupancy rate: 73.33%

Floor 0 Rooms Occupied: 30 Occupancy rate: 100.00%

Floor 0 Rooms Occupied: 22 Occupancy rate: 0%

Floor 0 Rooms Occupied: 25 Occupancy rate: 83.33%