|
That was not funny. You should crack jokes like these in some social communities.
|
|
|
|
|
Thanks for your answers, i got the way of doing it.
|
|
|
|
|
Hi, beginner programmer here, first post
I am writing a program that uses a arraylist of class part, and class Car consists of
Public Class Part
Public name As String
Public price As Double
End Class
Public Class Car
Public name As String
Public parts As New ArrayList
End Class
There is an ArrayList of Part and I would like each Car to consist of various Parts and the price would be totaled for a Car etc.
I would like to be able to change the price of a Part and if a Car contains that part I will be able to retotal the new amount.
By using something like
Car.parts.Add(partArraylist.Item(i))
Am i adding a copy? reference?
Any advice would be great, or am i approaching it the wrong way?
Thanks
150
|
|
|
|
|
Unless you're using VB 1.0 or 1.1, you should never use the arraylist class. Although I guess in VB it doesn't matter b/c the language is weakly typed, but ideally you should use generic collections such as List<Car> ( I think it's List(Of Car) in VB ).
150db wrote: By using something like
Car.parts.Add(partArraylist.Item(i))
Am i adding a copy? reference?
If Part is a class, you're adding a reference, if it's a struct, you'd be adding a copy. So, yes, you could do that, and then change the price of the part, and all the cars with that part, should reflect the new price. Then you can have a method in the car that iterates over it's parts, adds them, and comes up with a total.
What if a car has more than one of the same part ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for the reply, very helpful, forgot all about generics.
Yes a car is able to have more than one part, ie 4 wheels. Havent thought how to implement it yet, could I do something like,,
Public Class Car
Public name As String
Public parts As New List(Of Part)
Public quantity As New Hashtable
End Class
And have the key as the partname and the value for quantity?
|
|
|
|
|
150db wrote: Public quantity As New Hashtable
Now you have forgotten about generics again.
Public Quantities As New Dictionary(Of Part, Integer)
An alternative would be to create your own generic class Qantified(Of T), that just contains an Integer for quantity and a T variable. Then you could do:
Public Parts As New List(Of Quantified(Of Part))
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hi
how can i detect a connection string in a program?
i want to detect a connection string in a program and find the database that the program connect to it.
i am writing a program that when it add to other program with sql database it must detect the connection string and the database that the program connects to it... please help me...
|
|
|
|
|
well, this sounds nasty, but, really what you want to do is load the whole program and it's config files as binary data, then go through it looking for something that matches a regex designed to find connection strings.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i thik that your way is difficult... isnt there any way to answer this question? all the databases are sqlserver
|
|
|
|
|
Well, you could use black magic I suppose.
You have a binary file and you want to find connection strings in it. How do YOU propose to do that ? You MAY be able to write code that detects attempts to connect to a SQL Server, and find them that way. A more obvious approach is to look for SQL Servers that can be seen and then look to see what DBs they have, that would be a ton easier. It won't tell you which DB belongs to which program, obviously.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
how can load the whole program as binary data?
|
|
|
|
|
File.ReadAllBytes. Getting those bytes into strings that you can then run a regex on, is another matter. I guess you need to look for sequences that look like a string. I think the whole thing is a disaster. I assume you're assuming that the string is not in a config file, seeing as you're trying to hack into an existing program.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i cant undrestand you plese help me... i must write this program till this evening isnt there any other way?
|
|
|
|
|
Why do you have to write it this evening ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i must deliver it to my boss. i am a programmer and its a piece of our projects
|
|
|
|
|
Your boss gave you one night to write something, but when it's explained to you, you can't understand the explanation ? Your boss is an idiot.
I've explained every possible way to do this that I can think of, in the plainest possible language. I don't know what else to say.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i can undrstand you but i want just to know is there any other way? you are right... i am sorry... thank you for your help my good friend anyway
|
|
|
|
|
Hey guys,
Is there any body that worked on archive? Right now I am working on small application, which does the archive and the code was written in vb.net. It copies the database and zip that file and send that zipped file to write a DVD. This application works fine for small file but its giving error when we have data like 5 GB its giving error as below
ICSharpCode.SharpZipLib.Zip.ZipException: Maximum entry size exceeded
If any body can help, it will be grate …….appreciate your time. Thank you………
|
|
|
|
|
You should create a multi part zip, not a single 5 gb file.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
hey Christian Graus,
Thank you very much for ur reply. but, please can u tell me how can i use multi part zip. i have no clue about that. i have a 5 GB database i need to archive that.
Thank you for ur time.....
|
|
|
|
|
As Christian has said, do multi-part file and just have a way to be able to work with all the parts when unzipping.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Not sure whether to put this query into the database section or here, but here goes.
I have a SQL Server database with a table of contacts (about 130,000 records). Each contact is a member of a category (9 different categories). What i need to do is count how many contacts are in each category for output in my vb.net application.
I can think of 2 methods to do this (actually 3 but the third is a definate no), which would you recommend.
Method 1 : Use a Cursor in a SQL Server stored procedure to iterate through all the contacts keeping a count of contacts in each category.
Method 2 : Get the data from the database and do the processing in my application.
Which approach do you think would ofrer the best performance?
(In case you were wondering, the 3rd method involves calling a stored procedure 9 times, once for each category and doing the count)
|
|
|
|
|
Since option 1 mentions access to stored procedures, why not write a stored procedure to return the data in one call? If the categories exist in a table, then you should be able to join on that table.
And this should be in the database section...
Tim
|
|
|
|
|
It is relatively easy to do in sql, depending on your database structure. If you give a few more details of the database structure I am sure it will be easy to write a sql query - after all, its this type of thing sql was designed for.
Liqz wrote: Method 1 : Use a Cursor in a SQL Server stored procedure to iterate through all the contacts keeping a count of contacts in each category.
Slow. Only ever use cursors if you have process on a record by record basis
Liqz wrote: Method 2 : Get the data from the database and do the processing in my application.
Could do, but you are return large volumes of data which again, you would end up processing on a record by record basis.
If the data is held in a link table something like
contactid, categoryid
The query is
select categoryid, count(*) from links group by categoryid
or, if its a single column on the contacts table with different values
select categoryid, count(*) from contacts group by categoryid
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Don't do cursors, but rather go with stored procedures. You'll be better off performance-wise.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|