Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all 26101 articles
Browse latest View live

Adding a price to a listbox from a item from another listbox...

$
0
0
Getting stuck on this I know it's simple and maybe I'm just over thinking it...Help is much appreciated.

In the CLICK events for the Add buttons on both the Audio Books and Print Books forms, add the selected item to the Shopping Cart listbox on the main form and add its corresponding price to the Costs listbox on the main form.

I've tried multiple things but at a loss...


Code:

Option Strict On

Public Class Form1


    Public Const decSALES_TAX As Decimal = 0.06D
    Public Const decSHIPPING_CHARGE As Decimal = 2

    Public printBookPrice() As Decimal = {11.95D, 14.5D, 29.95D, 18.5D}
    Public printBookName() As String = {"I Did It your Way", "The History of Scotland", "Learn Calculus in One Day", "Feel the Stress"}
    Public audioBookPrice() As Decimal = {29.95D, 14.5D, 12.95D, 11.5D}
    Public audioBookName() As String = {"Learn Calculus in One Day", "The History of Scotland", "The Science of Body Language", "Relaxation Techniques"}

    Private Sub mnuReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuReset.Click
        lblSub.Text = String.Empty
        lblTax.Text = String.Empty
        lblShipp.Text = String.Empty
        lblTotal.Text = String.Empty
        lstboxCart.Items.Clear()
    End Sub

    Private Sub mnuPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPrint.Click
        frmPrintBooks.Show()
    End Sub

    Private Sub mnuAudio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAudio.Click
        frmAudioBooks.Show()
    End Sub

    Public Sub DisplayCharges()
        Dim BookTotal As Decimal = 0
        For Each Book As String In lstboxCart.Items
            If Book.StartsWith("A") Then
                BookTotal += audioBookPrice(CInt(Book.Substring(1, 1)))
            Else
                BookTotal += printBookPrice(CInt(Book.Substring(1, 1)))
            End If
        Next
        Dim BookCount As Integer = lstboxCart.Items.Count
        lblSub.Text = BookTotal.ToString("C2")
        lblTax.Text = (BookTotal * decSALES_TAX).ToString("C2")
        BookTotal += BookTotal * decSALES_TAX
        lblShipp.Text = (BookCount * decSHIPPING_CHARGE).ToString("C2")
        BookTotal += BookCount * decSHIPPING_CHARGE
        lblTotal.Text = BookTotal.ToString("C2")

    End Sub


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


    Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click
        MessageBox.Show("The Shopping Cart System allows customers to shop for both Print and Audio Books.", "Shopping Cart About")
    End Sub

    Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
        If lstboxCart.SelectedIndex <> -1 Then
            lstboxCart.Items.RemoveAt(lstboxCart.SelectedIndex)
        End If
        DisplayCharges()
    End Sub


End Class

Code:

Option Strict On

Public Class frmAudioBooks

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

    Private Sub btnAddaudio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddprint.Click
        Form1.lstboxCart.Items.Add(lstAudiobooks.SelectedIndex & ": " & lstAudiobooks.SelectedItem.ToString)
        Form1.DisplayCharges()
    End Sub

    Private Sub frmAudioBooks_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For x = 0 To UBound(Form1.printBookName)
            lstAudiobooks.Items.Add(Form1.printBookName(x) & " " & String.Format("{0:C}", Form1.printBookPrice(x)))
        Next x
    End Sub


End Class

Code:

Option Strict On

Public Class frmPrintBooks

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

    Private Sub btnAddprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Form1.lstboxCart.Items.Add(lstPrintbooks.SelectedIndex & ": " & lstPrintbooks.SelectedItem.ToString)
        Form1.DisplayCharges()
    End Sub

    Private Sub frmPrintbooks_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For x = 0 To UBound(Form1.printBookName)
            lstPrintbooks.Items.Add(Form1.printBookName(x) & " " & String.Format("{0:C}", Form1.printBookPrice(x)))
        Next x
    End Sub
End Class


VS 2013 Change form size based on selected tab

$
0
0
I'm currently working on a project which involves a TabControl and I would like to know if it's possible to automatically change the size of the form based on the selected tab.

As an example, if the user selects Tab1, the form resizes to 200x200. Then if the user selects Tab2 the form resizes to 300x300. Switching back to Tab1 will resize the form to 200x200.

Thanks.

VS 2010 TryParse and Listbox help

$
0
0
Alright, so I'm having 2 problems with 2 small programs I am trying to make. I am fairly new to VB, so the help is greatly appreciated.

The first thing I'm trying to do Is use TryParse to validate that the user has input a number (integer and decimal) into 2 textboxes.

The other things I'm trying to do, with a listbox, is to: 1. have a button that moves the selected listbox item to another listbox. And 2. Have a button that adds text (an asterisk *) to an existing listbox item.

I'll add any additional info if needed. Thanks.

Can a program update itself without having to manually update it?

$
0
0
For example if i have a program and i added a minor update.
Can my clients have their program updated without manually updating it?

Need help with some basic VB for homework!

$
0
0
Can you guys help walk me through some of this homework? This is a new class to me, as my major is networking, and I don't seem to be quite getting it just yet. I'm still adapting to learning the proper syntax.

For my homework, it told me to make a form, place some labels to match up with textboxes/a combobox for input, and now I'm at a part where it's asking me to create a class and I'm still a tad confused about what exactly a class is.



I'm currently stuck on question 3 - anyone care to help walk me through some of it?

Here is my progress up until this point, so you can see what my current form looks like.

VS 2012 [RESOLVED] Need to find File CRC

$
0
0
I am trying to determine a File CRC (Cyclical Redundancy Check). Is this built into VB, or can anyone point me to some code. I looked in the code bank but could not find any.

VS 2010 my controls are not refreshing ?

$
0
0
Hello,

I have a form with a combobox on. When i click on the cbo I use the selectedindexchange event to refresh some data in my control:

Code:

Code:

Private Sub cboRecipeName_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles cboRecipeNames.SelectedIndexChanged        If xChangeLoadedRecipeAllowed Then
            If cboRecipeNames.SelectedIndex > -1 Then
                RecipeFromBook2Screen()
            Else
                cboRecipeNames.Text = 0
            End If
        End If
    End Sub

This works perfectly, in my sub RecipeFrombook2Screen is send the required info to the screen. Part of the code:

Code:
Code:

MessageBox.Show(oTempRecipe.sRecipeName)
        cboRecipeNames.Text = oTempRecipe.sRecipeName
        nudRecipeSteps.Value = oTempRecipe.iNbrSteps
        chkCycle.Checked = oTempRecipe.Cycle
        nudNrCycles.Value = oTempRecipe.iNrCycles
        txtTime.Text = oTempRecipe.iTime
        txtPressure.Text = oTempRecipe.iPressure
        txtcode.Text = oTempRecipe.scode
        MessageBox.Show(oTempRecipe.scode)

of course the messageboxes are shown, with the correct data and the controls are filled with the correct data.
The problem happens when I change the selectedindex of the cbo through code in an other function.

Code:
Code:

  Public Sub changeRecipeThroughScanner(ByVal s As String)
        sCode = s
        TextBox1.Text = s
        Dim xFound As Boolean = False
        Dim iIndex As Integer = -1
        Do While Not xFound
            iIndex += 1
            Dim cboItem As clsCboItem
            cboItem = cboRecipeNames.Items(iIndex)
            If cboItem.ExtraInfo3.Equals(s) Then
                xFound = True
            End If
        Loop


        If xFound Then cboRecipeNames.SelectedIndex = iIndex
        ' RecipeFromBook2Screen()
    End Sub

The index is changed, so the selectedindexchanged event is fired, the messageboxes are appearing on my screen with the correct information, but the controls are not updating? But when I follow the function with debug, the correct information is send to the control. It is like they are not updating/refreshing. Someone has an idea what can cause this?

kind regards,
Wesley

VS 2010 RESOLVED - Math Question (Discounts and such)

$
0
0
Hello all,
This pertains to processing sales orders for a retailer.
A dollar or percentage discount can be given to an individual item in an order.
On top of that, a percentage discount can be given to the order as a whole (in which case, this percentage off is applied to each individual item in the order).

Let's say an item costing $100 is discounted $20. So the price of the item at this point is now $80.
At the end of the sale, a 30% overall discount is applied to the order. So now 30% off of the $80 (not $100) is taken for the item described above, thus discounting the item $24 more.
So the total amount off of the item is $44, and the customer pays $56 for that item.

Now - if at some later time, we wanted to look at data to reconstruct what happened on that sale, would it be possible to do so given only these three pieces of information:
Regular Price of Item = $100
Total Amount Off = $44
Order Level Discount = 30%

In other words, is there an equation that can be used to determine what portion of the $44 was a result of the 30% discount, and portion was the dollar discount?

Multiplayer game client...

$
0
0
Guys i know how to make game server
but i can't make game client :(
i need any tutorial to explain how to make game client
i don't need and advanced game client
just i need to make and TIC TAC TOE online game
i have source of this game but it's not online soo
if some one post an tut link for tic-tac-toe online game [SERVER/CLIENT]
or any online game tutorial it will be amazing :P

VS 2010 Question about Access database Connected with VB

$
0
0
Hi ,
am kind of in conflict here
I created a database using access

table name is appraisal table
three columns

Research Paper , Conference , Others

Research Paper = 10 Points
Conference = 5 Points
Others = 3 Points

Anyway what I want to do is the three columns type is checkbox

create data grid view in visual basic and load appraisal table

when user run the program and checkbox all of them it should show 18 points in a label , or textbox , or anywhere ;P

how can I do that ?

finding filenames from HTTP GET

$
0
0
I'm using a webbrowser control to browse a website, and sometimes I want to be able to catch the filename of a file that is downloaded so I can manipulate it with my program. I don't know what the filename will be, but I know what type it is.now I've been following the activity of the website using the firefox Network monitor tools and I can see that in a particular GET request, there is a content disposition that includes my filename "myfile.csv" ... is there any way using the webbrowser that I can get hold of the GET reponse, extract this an then use it in my code? I think that 'no' is the obvious answer for the webbrowser on its own, but I was wondering if there is anything else in .net that allows me to get hold of this? I've had a look at http listener and so on, but it seems a bit beyond me, and some of the projects I have found online seem to be old and/obsolete and there are various issues with more recent versions of windows.

thanks!

VS 2010 vb.net new XLM by gived XSD file

$
0
0
Hi developers :)
Here is my issue:
I have to update data in a web site, and the owner of that site gived me a XSD file, wich gives me the schema in order to make a XML file.
I have my project made in vb.net (VS2010) and I'dd like to create programmatly the XML file.
I'm reading all over the web, but I can not find some help...
Conclution I have:
- existing vb.net project
- XSD file
- data

How can I create a XML file that respect the gived XSD file in order to update all data in once ?
I really hope somebody can help me with this.

Thank you in advance
Dario

VS 2010 Database Clears When Application Closes

$
0
0
So When I Input The Data It's There But When I Close And Reopen It Clear's the database

How Could I Fix This Problem?

Could not copy

$
0
0
Sometimes when I start my VB project from VS2013 I get 2 errors:
Error 11 Could not copy "obj\x86\Debug\Coordinator2.exe" to "bin\Debug\Coordinator2.exe". Exceeded retry count of 10. Failed.
Error 12 Unable to copy file "obj\x86\Debug\Coordinator2.exe" to "bin\Debug\Coordinator2.exe". The process cannot access the file 'bin\Debug\Coordinator2.exe' because it is being used by another process.
If it happens I close the project, open it again and everything works. When I met this for the first time I spent pretty much time on looking for a source of the problem.
Is it a Visual Studio bug?

Thank you,
Vlad

[RESOLVED] Get a field value of current row in BindingSource

$
0
0
Hi all.

I am in the process of cleaning up my code as much as I can. Currently, if I need the value of one field of the current record I do something like:

strName = PeopleBindingSource.Current("Name")


It works fine and it is explicit. But Option Strict gives me a late binding error here. Is there another way of accessing that value and still be explicit enough that we can see the name of the field in the code instead of an index number?

Thank you

Convert Image to a VALID icon

$
0
0
I need help converting an image to a valid icon.

I can save the image as an Icon, no problem. BUT, when I try to use this Icon for it's intended purpose (just as either a project icon, or shortcut icon) .. an error appears telling me it is not a valid icon.

Code:

 
Dim bmp As New Bitmap(Path & shortLabel & "\" & imgName)
bmp.Save(Path & shortLabel & "\newIco.ico", System.Drawing.Imaging.ImageFormat.Icon)

Any solutions? Ideally without needing extra DLLs that would have to be included with my project, but if that's what it requires then so be it.


Thanks for your time.

InitializeComponent takes too long

$
0
0
One of the WinForms in my VB project loads very slow. I set several breakpoints and found out that InitializeComponent() takes more than 10 seconds. If I push F8 in order to see where it takes the time inside of InitializeComponent() it doesn't bring me anywhere, it just increases the delay to 25-35 seconds. If I click Continue button it takes more than 10 sec.
The form contains 253 controls. Some of them from Infragistics. Please do not suggest to decrease the number of controls by putting them on another form etc. This project is the conversion of the existing VB6 project and the apearance of the screens must be as close to VB6 as possible.
May the number of controls affect the performance so much?
Or there is another reason?

Thank you,
Vlad

VS 2013 String Manipulation (Left, Right) alternatives.

$
0
0
Code:

If STRING1.StartsWith(Microsoft.VisualBasic.Left(STRING2, 3)) Then
Code:

If STRING1.EndsWith(Microsoft.VisualBasic.Right(STRING2, 3)) Then
What is the correct way to do the above please?

Removing the Microsoft.VisualBasic.Left / Right

Having Problems with KeyDown/KeyUp Event...

$
0
0
So I'm trying to solve a problem that I was working on in high school which was back in 2001 or so. I did a little research and I'm pretty sure we were using VB 6.0 at the time and not a .NET version. Anyways, at the time I was trying to code collision detection between 2 PictureBoxes, I was having problems because my understanding of programming was extremely limited. But now that I'm older and that I've learned some Java and C++ I want to conquer this old problem, but now I've hit a road block :( I would imagine that the manor in which VB now handles KeyDown/KeyUp has evolved.

I'll type the logic out in pseudo code.
At the time I'm pretty sure I had:

MainTimer was = true
MoveLeftTimer was false

MainTimer(){
if(LeftKey == KeyDown) then
MoveLeftTimer.enabled = true
if(LeftKey == KeyUp) then
MoveLeftTimer.enabled = false
}

MoveLeftTimer(){
Picture1.left += 1
}

At the time this was working.
So if Picture1.left = Wall.left then I would say LeftTimer.enable = false and the Picture1 would stop moving left.
But now if I used they KeyDown/KeyUp Event in a similar fashion the Picture1 will stop for a second and then continue through the Wall.

So I'm guessing that the MoveLeftTimer DOES get disabled when it reaches Wall.left but because I'm holding down the arrowKey that says MoveTimerLeft.enable = true it overwrites something or whatever.

I can post the code I have if need be. But basically what other method are there for using key presses?

VS 2013 Get X, Y of 1 pixel of a color in a image?

$
0
0
Hi all, I am currently making a little project [Image Find and replace] in which the user loads a image into the form, and selects a color from a combo box, And selects a new color to replace it with.
The problem I am facing is that I want to take the image supplied and find the color the user specified and get the X and the Y of 1 pixel in which contains that color [Plan to use a loop and loop through each pixel containing that color and draw over it with the other color.

Could anyone point me in the right direction to do so? :)

If some one could help me out I would be very grateful :D
Viewing all 26101 articles
Browse latest View live




Latest Images