• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Visual Basic help here please!

Status
Not open for further replies.

Relix

he's Virgin Tight™
Jin34 said:
Code:
Public Class Form1
    ' Class level structure para el arreglo donde estaran los tax rates

    Public Structure sRates
        Public intLowerLimit As Integer
        Public intUpperLimit As Integer
        Public dblSingleRate As Double
        Public dblMarriedRate As Double
    End Structure

    ' Class level arreglo.
    Public taxRates() As sRates

Public taxRates(intMaxSubscript) As sRates

or
Public taxRates(5) As sRates
 

Jin34

Member
Relix said:
Public taxRates(intMaxSubscript) As sRates

or
Public taxRates(5) As sRates

Weird, I was under the impression I didn't have to be specific. I'll use the number since the rest of the code follows that pattern and I have to differentiate.
 

Chris R

Member
Ya the array needs to be initialized with enough space for every line you will be reading in. There are better data structures to use, but for the time being you can just initialize with with a static value. Just understand that this isn't the best way to do things.
 

Jin34

Member
I initialized the array to (5) but now I get a different error on the same line.

585Zl.png
 

Relix

he's Virgin Tight™
When it reads the data it reads it as a string, not as an integer. You can try CStr or just not type anything at all. Option Strict On won't let you do it without CStr though.
 

Chris R

Member
Your taxdata(0) string is a "," instead of for instance "1000"

Set a breakpoint on that line and analyze taxdata() to see if it is reading in the file correctly.
 

wolfmat

Confirmed Asshole
I think the comma comes from a big number, so you might have to either convert differently or check for and skip commata (and concatenate the stuff before and after that comma).
 

Chris R

Member
wolfmat said:
I think the comma comes from a big number, so you might have to either convert differently or check for and skip commata.
Will be hard if they are using commas to delimit each value on every line.
 

wolfmat

Confirmed Asshole
rhfb said:
Will be hard if they are using commas to delimit each value on every line.
Yeah, the commata are probably rather standard CSV delimiters. Sorry then.

Jin, you used Split() wrong. The first argument is supposed to be the String to split. The SECOND argument is the delimiter.
 

Jin34

Member
00000, 10000, .00, .00
10001, 20000, .06, .05
20001, 50000, .09, .08
50001, 200000, .08, .09
200001, 500000, .15, .12
500001, 999999, .30, .25

That's the data I'm trying to put in the arrays, the comas are supposed to be used to separate where each part goes to.
 

wolfmat

Confirmed Asshole
It's this:
Code:
Dim taxdata() as String = Split(strLine, chrDelimiter)

Otherwise, you are trying to split the string "," without a delimiter ,)
 

Chris R

Member
Ya you are using Split( ) wrong. I totally missed that heh. You aren't actually splitting the line you are reading.

edit: stringToSplit.Split(thingyToSplitOn) should work too.
 

Jin34

Member
Ah thanks, it works now except the end result is telling me he will pay $0.06 in taxes. I made JayDubya's dream tax calculator lol

Oh nm, I noticed the really dumb thing I did
 

Relix

he's Virgin Tight™
Aaah my dear friend VB. Taking another programming course and I have hit a massive roadblock.

I must design a database-driven Car Repair Shop (professors love this I think). Now, the thing is... I have missed quite a few classes due to work reasons and I am kinda lost. I have the general know how but I am just freaking lost. So let me explain!!

I just need one basic thing which will let me complete most of this but as said, I am stuck.

I have a textbox, a search button, some label fields for last and first names...

Then I have a DataGridView (requested by the prof) that will display the information I search from that textbox.

My great question is... HOW THE FUCK DO I DO THIS?? Driving me insane, I know I am close but I just can't grasp it. I made a query in the dataset, specifically the Customer table where I need to search for this info.

SELECT fldCustomerId, fldLastNames, fldFirstName, fldAddress1, fldAddress2, fldCity, fldCountry, fldZipCode, fldCustomerType, fldRemarks, fldDiscountPercent, fldStatus
FROM tblCustomers
WHERE fldFirstName LIKE + '?'

That WHERE being the wild card. I think its missing a % there but I'll get to that later.

Now, my main issue is... how the hell do I make this work? I think I can create a FillBy method or somewhere along the lines but I am lost on what to do. Help me GAF... you are my only hope! XD!
 

Chris R

Member
VB.net? Get into design view and setup your schema after making sure you have selected the data source.

For the SQL you can do LIKE '%' + 'your value here' + '%' for a wildcard.
 

Relix

he's Virgin Tight™
rhfb said:
VB.net? Get into design view and setup your schema after making sure you have selected the data source.

For the SQL you can do LIKE '%' + 'your value here' + '%' for a wildcard.

Yeah this part is fixed...

SELECT fldCustomerId, fldLastNames, fldFirstName, fldAddress1, fldAddress2, fldCity, fldCountry, fldZipCode, fldCustomerType, fldRemarks, fldDiscountPercent, fldStatus
FROM tblCustomers
WHERE fldFirstName LIKE ? + '%'

And I also have a search button where...

Private Sub SearchCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Me.TblCustomersTableAdapter.FindCustomer(CustomersCarsAndRepairsDataSet.tblCustomers, txtFindCustomer.Text)
End Sub

Now, my main dilema is displaying this searched information in two labels and a Data Grid View. The DGV auto loads, and if I add the query directly through it it creates a stupid search toolbar that actually does what needs to be done but I can't use it like that. SO!

This is the Data Grid View Code, atm:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CustomersCarsAndRepairsDataSet.tblCustomers' table. You can move, or remove it, as needed.
Try
Me.TblCustomersTableAdapter.FindCustomer(Me.CustomersCarsAndRepairsDataSet.tblCustomers, txtFindCustomer.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try

End Sub

It doesn't update after the search so I am definitely doing something wrong. Very stupid wrong.

Well shit it worked after a second run. lol
 

Relix

he's Virgin Tight™
Ok with that done comes the next beautiful step!! After I select a name from the DataGrid it needs to pass on to other forms as well, I have a vague idea but it isn't working that well right now :p!

If dgvCustomers.Rows.Count > 1 Then
strCustomerInfo = dgvCustomers.CurrentRow.Cells(0).Value.ToString()

End If

Vehicles.ShowDialog()

I am so burned out by now.
 

Chris R

Member
Create the other form and then pass it whatever property it needs before calling show on it.

And can you use a column name/id instead of the index? Don't have msdn open in front of me right now, but that helps make your code just a little cleaner.
 
Anyone able to give some VB help? I'm also trying to create a two dimensional array with a lookup feature. Up until this point I've had a decent understanding of the logic but now thats all gone. But I can sense the answer is so simple! I'm just not looking at it correctly.
 

Relix

he's Virgin Tight™
In another episode of Relix is annoyed by VB! I am using VB.NET (Web Developer) and making a website for a class project. The whole thing is basically laid out but I need to save a cookie when a button is pressed, not big deal... the problem is I am having problem executing the command. Gives me a compilation error.

So, in the Markup file I have the following Code:

<asp:Button ID="btnCustomerMaintenance" runat="server"
Text="Customer Maintenance" Width="153px"
onClick="btnCustomerMaintenance_Click"
PostBackUrl="~/CustomerMaint.aspx" />

And the codebehind file has this so far:
Protected Sub btnCustomerMaintenance_Click(ByVal sender As Object, ByVal e As System.EventArgs)


End Sub


The thing still gives me the following error:



Compiler Error Message: BC30456: 'btnCustomerMaintenance_Click' is not a member of 'ASP.default_aspx'.


What in blazes am I doing wrong!
 

Relix

he's Virgin Tight™
Try adding "Handles btnCustomerMaintenance.Click" to the end of your function declaration.


Gives me another error in Web Developer......

Error 3 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. C:\Users\Relix\Documents\Visual Studio 2010\WebSites\Car Repairs Web Version\Default.aspx.vb 7 109 C:\...\Car Repairs Web Version\
 

Chris R

Member
Does the button variable in your designer file have "WithEvents"? I guess it would look like this

Protected WithEvents btnCustomerMaintenance As Global.System.Web.UI.WebControls.Button
 

Relix

he's Virgin Tight™
Does the button variable in your designer file have "WithEvents"? I guess it would look like this

Protected WithEvents btnCustomerMaintenance As Global.System.Web.UI.WebControls.Button


Tried... nop. The button doesn't have WithEvents anywhere. Also, the codebehind file doesn't detect a dropdownlist I need to get a value from, says it doesn't exist.

Oh I am going mad. :p!
 

Chris R

Member
Are you using Visual Studio to do this? And did you start a new ASP.Net project? Because yea, that stuff should be really easy to get working :|

I just made a brand new page in a project I'm working on right now, added a button and drop down list, and was able to get the selected value from the drop down after the button was clicked just fine. Are your buttons/dropdowns showing up in intellisense?
 

Ecrofirt

Member
Gives me another error in Web Developer......

Error 3 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. C:\Users\Relix\Documents\Visual Studio 2010\WebSites\Car Repairs Web Version\Default.aspx.vb 7 109 C:\...\Car Repairs Web Version\


You didn't do like a whoopsie where you are declaring your function outside of the scope of your form or whatever, did you?

Not familiar with ASP.NET stuff, but the first error you gave sounded like something might have been out of scope.
 

Relix

he's Virgin Tight™
Are you using Visual Studio to do this? And did you start a new ASP.Net project? Because yea, that stuff should be really easy to get working :|

I just made a brand new page in a project I'm working on right now, added a button and drop down list, and was able to get the selected value from the drop down after the button was clicked just fine. Are your buttons/dropdowns showing up in intellisense?


I know >_<! Yeah I made a new ASP Net project... Empty too. Have 8 forms....

Using Web Developer 2010... I know it should definitely work. Don't know what the fuck is going on. It doesn't even "detect" the other DropDownList I am using in the code behind. Ugh... =/
 

Relix

he's Virgin Tight™
You didn't do like a whoopsie where you are declaring your function outside of the scope of your form or whatever, did you?

Not familiar with ASP.NET stuff, but the first error you gave sounded like something might have been out of scope.


Since its .NET I have two forms. One is the HTML one with the ASP Commands, and the other is the codebehind file which has the actual programming.
 

Chris R

Member
Ok just made a brand new project, tested stuff and this all worked.

Code:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApp._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
		<asp:Button ID="theButton" runat="server" Text="Click Me!" />
		<asp:DropDownList ID="theDDL" runat="server">
			<asp:ListItem Value="0">0</asp:ListItem>
			<asp:ListItem Value="1">1</asp:ListItem>
			<asp:ListItem Value="2">2</asp:ListItem>
			<asp:ListItem Value="3">3</asp:ListItem>
		</asp:DropDownList>
    </div>
    </form>
</body>
</html>

And in the code behind

Code:
Protected Sub btnClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles theButton.Click
	Dim v As Integer = theDDL.SelectedValue
End Sub

Does your stuff look anything like that?
 

Relix

he's Virgin Tight™
Ok just made a brand new project, tested stuff and this all worked.

Code:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApp._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
		<asp:Button ID="theButton" runat="server" Text="Click Me!" />
		<asp:DropDownList ID="theDDL" runat="server">
			<asp:ListItem Value="0">0</asp:ListItem>
			<asp:ListItem Value="1">1</asp:ListItem>
			<asp:ListItem Value="2">2</asp:ListItem>
			<asp:ListItem Value="3">3</asp:ListItem>
		</asp:DropDownList>
    </div>
    </form>
</body>
</html>

And in the code behind

Code:
Protected Sub btnClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles theButton.Click
	Dim v As Integer = theDDL.SelectedValue
End Sub

Does your stuff look anything like that?

AAARGHH!! How in the hell did the PageLanguage header get deleted. What the fuuuuck that was it. I am gonna kill somebody brb.

1 hour lost on that shit... Fuck. Thanks a million rhfb
 

Relix

he's Virgin Tight™
Last time I am gonna ask something hahhaa.

Program is fully functional, running, no crashes, everything just perfect. I do need a little help with a SQL Query. I gotta calculate (in the query) the value of another field I need to create in the query. Now, I know how to display it and everything, but I am having two logical issues that I can't wrap my head around

1. The percentages are whole numbers. Not .1 like one would usually transform in a code, so... how can something similar be done in a query?

2. This is basically the query but VB is bitching about it

SELECT [fldChargeAmount * fldDiscountPercent]
AS calTotalDiscount
FROM [tblOrderCharges];

But the program is bitching. I must admit I am absolutely horrible at SQL and queries so.. yeah I probably fucked up something there lol. Of course that query would fail given that percentages are whole numbers and not fractions, but yeah... So... if anyone can help me with that last bit there I would eternally love him :p. Its basically what's left of my project.

BTW, am I the only person who studies/takes VB Courses aside from rhfb and Fersis? :p!
 

Chris R

Member
Try this in the SQL Query

SELECT [fldChargeAmount] * [fldDiscountPercent] AS calTotalDiscount
FROM [tblOrderCharges];

The [] is just basically letting the query know the exact column/table/ect name, but are only really needed if the column/table name has a special character in it.
 

Relix

he's Virgin Tight™
Try this in the SQL Query

SELECT [fldChargeAmount] * [fldDiscountPercent] AS calTotalDiscount
FROM [tblOrderCharges];

The [] is just basically letting the query know the exact column/table/ect name, but are only really needed if the column/table name has a special character in it.

Kinda figured that just as I came back to edit the post, lol. I worked it as


SELECT fldChargeAmount * (fldDiscountPercent * .01) AS calTotalDiscount
FROM tblOrderCharges;


This is the query for that grid view.. I kinda need to merge those two together but I am failing at every corner lol:

SELECT * FROM [tblOrderCharges] WHERE ([fldOrderId] LIKE '%' + ? + '%')

EDIT: I am such a fucking idiot. Let me try making an outside data source... jesus lol.
EDIT2: The query works perfectly but the GridView gives me a render problem if I put two separate data sources. FML :p!
EDIT3: Wait wait nvm I think I got it. Still an idiot hahaha
 

Relix

he's Virgin Tight™
I am having one last issue... whole thing is running perfect, but I have a problem with a query and the grid view...

I have this query from a gridview:

SELECT fldChargeId, fldChargeReference, fldChargeType, fldRemarks, fldStatus, fldOrderId, (fldChargeAmount * (fldDiscountPercent * .01)) AS calTotalDiscount FROM tblOrderCharges WHERE (fldOrderId LIKE '%' + ? + '%')

The query works perfectly in the test, but when I load the page an ugly error pops up:

A field or property with the name 'fldChargeAmount' was not found on the selected data source.

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Any ideas?

Nvm got it... :p! Done with this. Thanks a million
 
Status
Not open for further replies.
Top Bottom