|
Ok im using VB.net, a console app.
I am making a database that stores games(members also, name, genre, rating)
i'm dividing the main code into some sub procdures and functions for easier readability.
So i have one sub for displaying the main menu(add, view..etc)
But now i wanna make a function to add a game to the array...
so i ask the user for the info, but how do i return all the values seperatly??
i tried assigning them directly to the
array(gameArray.name = console.readline()), but it doesnt work...
Any ideas will help!!
______________________________________________
"I'm not me when I dream...anymore." -TRUSTcompany
|
|
|
|
|
It sounds like you want to build a function that askes the user for three items and then returns those items so they can be used in anohter part of the program...
Buld a structure as so and declare it outside the function:
Public Structure InputData
Dim arg1 As type_name
Dim arg2 As type_name
Dim arg3 As type_name
End Structure
In your function create an instance of the structure, get all your input and assign each piece of input to each structure member:
Public Function GetInput() as InputData
Dim userResponse as InputData
'Get your input here
.
.
.
'assign each pice of input to your structure members
userResponse.arg1 = inputValue1
userResponse.arg2 = inputValue2
userResponse.arg3 = inputValue3
'return your data from the function
Return userResponse
Now you can call the function as so:
Dim returnData as InputData
returnData = GetInput()
From here if you want to pass it to another function to write the data to a DB you can simply do this:
Public Sub WriteDataToDB(inData As InputData)
'open the DB
'write each value to the DB
'you access each argument by the following
inData.arg1
inData.arg2
inData.arg3
.
.
.
End Sub
Hope that helps and I hope there are few typos
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Unknown wrote:
"I love long walks, especialy taken by those that annoy me."
|
|
|
|
|
Thanks Ray that kinda helps...
but i'm still not sure why i'm doing that...
Maybe i didnt explain it good enought..
I making an array, that has 3 members (name, genre, rating)
Overall i want a little menu
1) Add a game
2) Display a game
3) Show average rating of games
4) Quit
Something like that..so first i made a sub prodecure that displayed this menu (so i can call it after each option the user makes), that was all good
So the sub main looks like this so far
Private Sub Main()
Dim gamesArray() as Game 'Game is a declared structure above sub main)
Dim choice as integer
call DisplayMainMenu()
choice = console.readline()
End Sub
So then I started to do this:
Private Sub Main()
Dim gamesArray() as Game 'Game is a declared structure above sub main)
Dim choice as integer
call DisplayMainMenu()
choice = console.readline()
If choice = 1 then
* call AddGame()
End if
End Sub
Private Function AddGame()
console.write("Enter the game name: ")
name = console.readline()
console.write("Enter the genre: ")
genre = console.readline()
console.write("Enter the games rating: ")
rating = console.readline()
End Function
*** So my question being, if i get the info for the game in the function..
i somehow need to get all 3 pieces back up into the array...
Hope this clarifies things...
EDIT: Sorry forgot the IF
______________________________________________
"I'm not me when I dream...anymore." -TRUSTcompany
|
|
|
|
|
Hi
I was wondering how I would be able to assign a date to a date object.
Dim temp As Date
temp = ?
Thanks
Nitin
|
|
|
|
|
temp = #February 12, 1985#
you put any valid date expression between two #
|
|
|
|
|
I just installed VS.NET. Why is it that if I try to code in the html editor all the toolbox items are grayed out? However, if I go to design, they appear. Can I not use these buttons if I am coding by hand??
|
|
|
|
|
are you sure you're eding html ?
all items in the toolbox appear both in design and code when i open html file !!
|
|
|
|
|
Actually, the HTML tools are there, the ones I can't get to are the web form tools. I am editing ascx, aspx and they don't show unless I'm in design mode..
|
|
|
|
|
The use of apostrophes in a textbox, when using collaboration with a SQL statement causes trouble - i was wondering if theres any way to get around this - ie when inserting a value that contains an apostrophe, to omit it before using the SQL insert statement. Any help would be greatly appreciated!
|
|
|
|
|
You can use StringVar=StringVar.Replace("'", "") to remove the apostrophe from your string (where StringVar is your variable). There may be something more elegant, but this has worked for me.
|
|
|
|
|
You may want to think about using a parameterized query to pass the values into your SQL statement. Using the SQL Server data provider, it would look something like this:
<br />
Dim sql As String = "INSERT INTO Test (lname) VALUES (@LastName);"<br />
Dim cn As New SqlConnection(cnString)<br />
Dim cmd As New SqlCommand(sql, cn)<br />
cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = Me.TextBox2.Text<br />
cn.Open()<br />
cmd.ExecuteNonQuery()<br />
cn.Close()<br />
Doing it this way will save you the trouble of replacing characters in each input field and will help protect against some forms of SQL Injection attacks. However, it won't get you out of validating input for other constraints such as length, etc.
Hope that helps!
|
|
|
|
|
If you're trying to insert into a database, just double-up the quotes, so :
INSERT INTO table VALUES 'O'Connor'
becomes
INSERT INTO table VALUES 'O''Connor'
have some functions to do this, or just use a replace. This approach has the advantage that the string is stored with the apostrophe in place
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
I'm trying to deploy an application and I'm getting an error that a newer version of a control is needed. Here are the details
1) My app uses an Access database and references 'ADODB', 'ADOR', 'System', 'System.Data', and a few other normal System references.
2) When I setup the Deployment Project, it appears that the references are correctly identified as dependencies (ADODB.dll, and Interop.ADOR.dll are both listed).
3) When I try to run my installer application on a different computer (w/o .NET installed, but after installing the .NET Framework), I get an error.
4) The specific error is: "The .Net Data OLE DB Provider (System.Data.OleDb) requires Microsoft Data Access Components (MDAC) version 2.6 or later. Version 2.53.6200.0 was found and currently installed)"
I did some research (by looking in references in VB6, since I couldn't find what I needed in .NET) and found the Microsoft Data Access Components is in odbcconf.dll. I tried including that as a file/assembly in my Development Project, but when I built the project, it gave me the following error: "WARNING: 'odbcconf.dll' should be excluded because its source file 'C:\WINNT\system32\odbcconf.dll' is under Windows System File Protection."
So, my question is, how do I get that file upgraded? Or maybe I'm looking at the wrong place? The funny thing is that, that very same DLL on my computer is version 2.52, and the project installs (using the 'Install' menu option under 'Project') and runs fine. The other thing I've tried to do is include the 'Database_Access.msn' merge module. That didn't work. BTW, all computers I've been working on/with are Win2000/SP3 machines.
I have searched the MS help, MSDN, and was searching other websites when I found this message board, so I apologize if the info is readily available somewhere on this website.
Paul
One more question... why does the Development project give an error about requiring the .NET Framework to be installed on the destination computer, but if I try to add the Merge Module associated with it, it gives me an error saying that it should be excluded?!
|
|
|
|
|
ElseIf optSuppOrder.Value = True Then
Load deMain
With deMain
.SupplierOrderAudit_Grouping txtUser.Text, CDate(Text5.Text), CDate(Text6.Text)
End With
SupplierOrderAudit.Refresh
If SupplierOrderAudit.Visible = False Then
SupplierOrderAudit.Show
End If
End If
if the above option button is chosen, the intended purpose is that the report is generated. However, occasionally, when the command button is pressed, it throws the above run time error pointing to the report line, why is this? any help would be greatly appreciated or if you need any additional info.
|
|
|
|
|
Just plucking at straws but the error may occur if deMain is already loaded (e.g. not unloaded properly from a previous report???).
Maybe you should look into creating a new instance of deMain each time you need a report....
If this isn't where you are receiving the errors thenignore my post
Rhys Kirk
|
|
|
|
|
The error you mention generally occurrs when attempting to open an ADODB.Recordset object when it's already open - if you're reporting from a DB, this will prob be the cause, but suspect that it won't be in your code? Does that help?
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
dear all,
1) how do i trap the double click event on an item in a list view control (style = details)
2) how do i make Xp style tool tips (i.e. tool tip with cancel button in the top right corner)
thanx in adv
|
|
|
|
|
Q1) Isn't that with the DoubleClick event? and then you use the SelectedItems property to get the items that were selected, probably only 1 if it's a double click. If I'm wrong, sorry, I haven't messed with the List View control much yet.
|
|
|
|
|
Hi,
Is it possible to programatically access a Folder Properties...for example, A Folder can be shared on the network by right-clicking on it and going to the Sharing Tab. I want to be able to programmatically change/alter all options on the Sharing tab without right-clicking etc.
I am yet to find any articles or sample that can do this so any help would be greatly appreciated.
Many Thanks,
Rhys.
Rhys Kirk
|
|
|
|
|
Hi,
Can you suggest me a good book in Crystal Reports to be used with VB 6. I should know how to generate good reports by passing parameters,selection formula from vb.Also the book should give me a fair idea about subreports and linked
parameters.Can u suggest a good reference book or
anything.
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
Hi, Everyone,
I would like to encrypt .asp and .jpg files on CD. Does anyone know how to do it/
Thanks
qBAO
qBAO
|
|
|
|
|
Hi everyone i'm new to this VB.NET... i got a project to do and im stuck. it sounds simple but... here goes...
i need to assign a value($) to cities in a dropbox. then if they'er students you get a discount and if your going one way they get a discount. then print a total... i got the design already but i have no clue how to get the values in ... please help.....
thanks
sundragon
|
|
|
|
|
Do you mean the Combo Box control? If so then you use the Add method of the Items collection. ie. comboBox1.Items.Add("New Item")
|
|
|
|
|
Dim checkSQL As String
checkSQL = "SELECT OrderGenerate.OrderNumber, Client.Company, OrderGenerate.Completed " & _
" FROM Client INNER JOIN OrderGenerate ON Client.ClientCode = OrderGenerate.ClientCode " & _
" WHERE OrderGenerate.OrderDate= #" & dDate & "#"
Set RS = Conn.Execute(checkSQL)
If RS.BOF And RS.EOF Then
MsgBox "No orders yet today", vbExclamation, "No records returned"
Unload Me
Exit Sub
End If
The above is code that is located at the form load of the form. if no records are returned from the SQL statement, i wish the message box to be displayed and the form to be unloaded, however on run time, it crashes "object was unloaded" - is there anything i can do to fix this? any help would be greatly appreciated!
|
|
|
|
|
try this and let me know
<br />
If RS.BOF And RS.EOF Then<br />
MsgBox "No orders yet today", vbExclamation, "No records returned"<br />
Conn.Close<br />
rs.Close<br />
Set Conn=Nothing<br />
Set rs=Nothing<br />
Unload Me<br />
Exit Sub<br />
End If<br />
|
|
|
|