posted
Either way it doesn't matter I chucked away that line of code, and now voila it works it just doesnt like deleting mutliple rows at once. I don't even know why that line was needed or what it is for how can I begin to debug something if I dont even know what its for? And yes I checked the online documentation and I still do not know what the heck its for.
All I wanted to know is what was wrong with that line of code because as far as I can tell with the debugger everything is fine, I dont know what parameter index relates to, there is no variable called index. All I wanted was what is wrong and what I could do to fix it not the friggin secret of life.
IP: Logged |
posted
Blayne, why not answer my question? Do you talk to your classmates? How do THEY solve these problems?
What we are describing here, Blayne, is not some "abstract advice." It is the most basic element of what is in many of our opinions the most basic skill required of a programmer.
I am a professional programmer. I do most of my programming in ASP, although I prefer C# to VB these days for my codebehinds. The idea that .NET programming (or the Visual Studio UI) is so hard and so complex that you can't debug it is literally laughable -- and I mean precisely that; if you said that to another programmer, they would laugh you out of the room.
I strongly -- strongly -- advise that you begin to network with other students in your class. You need instruction in some very basic programming principles that, by your description, your professors have neglected. And if you can't count on your teachers to provide them, you're going to need to get them from somewhere before you'll be employable.
Posts: 37449 | Registered: May 1999
| IP: Logged |
quote:Originally posted by Blayne Bradley: google or ask other people.
But I don't believe those are the only options.
Posts: 6316 | Registered: Jun 2003
| IP: Logged |
Blayne Bradley
unregistered
posted
That is indeed what they did, we don't learn how to code in ASP, we learn how to use ASP to make a webbased user interface for an online store, our teacher does not have us try on our own to code what he cannot do himself. Hes advice with my issue is to simply cut down the code to do this:
KeyId = GrivViewRow.Rowindex
Thats it thats all, there may have been a solution to the other line of code but now at least I can finally delete rows.
Now I still have the problem that it wont delete multiple rows at the same time.
And why the heck does the Vista version for VS2005 not have a proper debug mode!?
IP: Logged |
posted
You are not learning how to make an online store. Any online store you try to make using these methods will be dysfunctional. Neither are you learning to program. You should complain about the quality of the course to your registrar. Heck, I'm near to complaining about the quality of the course to your registrar.
Posts: 15770 | Registered: Dec 2001
| IP: Logged |
Blayne Bradley
unregistered
posted
its done in milestones, this is #4, and we gradually add more layers to it, the ability to for example handle thousands of simultanious requests for example will be handled a little latter on.
IP: Logged |
quote:Originally posted by fugu13: You are not learning how to make an online store. Any online store you try to make using these methods will be dysfunctional. Neither are you learning to program. You should complain about the quality of the course to your registrar. Heck, I'm near to complaining about the quality of the course to your registrar.
I've been down that road before; complaining is a lost cause. It's the reason I never got my degree in Computer Science; I couldn't accept the futility of it all.
Posts: 3486 | Registered: Sep 2002
| IP: Logged |
quote:Originally posted by Blayne Bradley: As for those hours we were playing CK at the same time, so no soup for you!
Maybe you were playing CK. I wasn't. If I'd known you were, I'd have done something else with my time. No wonder you had difficulty with the concept, if you weren't even pretending to concentrate.
Posts: 10645 | Registered: Jul 2004
| IP: Logged |
Blayne Bradley
unregistered
posted
I am fairly certain we were in one of our sessions KoM and you were guiding me along through it, and then once the session ended we continued via icq.
IP: Logged |
quote:And why the heck does the Vista version for VS2005 not have a proper debug mode!?
In order to properly debug code in real-time in VS2005 when running on a Vista machine, it is necessary to run your instance of Visual Studio as an administrator. The easiest way to do this, assuming you have rights, is to right-click on the icon and choose "Run as Administrator" instead of double-clicking on the icon. You can also customize the icon, but any lab system worth its salt would remove that customization when you logged out.
Posts: 37449 | Registered: May 1999
| IP: Logged |
posted
In my experience, students do not get admin rights to blow their own noses when it comes to university lab computers. In many cases there are good reasons for this.
Posts: 10645 | Registered: Jul 2004
| IP: Logged |
posted
"In many cases there are good reasons for this."
Based on the guys I knew who were getting computer degrees, and/or worked in the computer labs in college, yes. More than half of them were worthless hardware-stealing trouble-making vandals. They gave intelligent geeky white guys a very bad name.
Posts: 3354 | Registered: May 2005
| IP: Logged |
Blayne Bradley
unregistered
posted
riiiiiiiiight I remember now vaguely that my teacher had difficulties and fixed it that way after 3 hours of googling.
And yes I do have admin rights. Advantages of making it to the third year, I also know how to get around nearly ever single firewall and proxy restriction as well.
IP: Logged |
quote:All I wanted to know is what was wrong with that line of code because as far as I can tell with the debugger everything is fine, I dont know what parameter index relates to, there is no variable called index. All I wanted was what is wrong and what I could do to fix it not the friggin secret of life.
And that's why I regret wasting my time and energy trying to help you.
You want someone to tell you what to do there. You need to learn how to debug. Right now, you will not be able to hold down or most likely get a programming job.
It would have been much easier for me to tell you what the extremely obvious problem was. I took the time and made the effort to basically lead you by the nose to debug it yourself. All you had to do was actually think about what I was saying and answer the question that I asked and you'd be on the road to learning some valuable stuff.
And all that time, you were just holding back whining "Just tell me what to do!" and weren't going to start thinking for yourself.
I realize that the message of "Stop being so ungrateful, self-centered, and lazy." is going to fly right past you, but maybe you could at least focus on "You need to learn how to debug code."
Posts: 10177 | Registered: Apr 2001
| IP: Logged |
posted
I'll just say that if you don't know what the phrase "parameter index" means, you will never be a programmer.
Posts: 37449 | Registered: May 1999
| IP: Logged |
posted
Um. I must say, I'm not actually totally sure what a parameter index is. It sounds like it should be an index into an array of function parameters, but I can't offhand think of a language that routinely lets you access parameters this way, unless it's Lisp. Conceivably you are being just a touch language-centric, tool-centric, or API-centric there?
Posts: 10645 | Registered: Jul 2004
| IP: Logged |
posted
Oh, wait, I get it now. Thinking too complicated there.
Posts: 10645 | Registered: Jul 2004
| IP: Logged |
Blayne Bradley
unregistered
posted
Look here's the issue: there are 3 rows, if I try to dleet the last 2 rows it dleets one, it merges the table so now it tries to delete a row that is nolonger there, I am doing a project all alone that was meant for 2 people to do, in not just this class but in about 3 other classes as well, odd number of people kinda left me out.
In the end my teacher told me to skip it, he'll accept just deleting one row at a time as he designed the course for people to work in 2 person teams not one person trying to handle the entire course load alone, especially when I don't even think a single team managed to get checkboxes to work, everyone else seems to have used buttons rather then chkboxes. I know how to debug, I know how to use the intermediate window, but VB is the only language I work with that uses this many methods, all other languages we were taught we built our own from scratch to learn how to do make our own algooithms.
Lets look at it this way, I made a line of code comparing the value of a txtbox and a lbl, how was I supposed to know you are supposed to put val(etc.text) there? To my view a number is a number is a number, didn't know that therwise it simply compares them to see which string is bigger.
IP: Logged |
quote:Originally posted by Blayne Bradley: [QB]I know how to debug, I know how to use the intermediate window, but VB is the only language I work with that uses this many methods, all other languages we were taught we built our own from scratch to learn how to do make our own algorithms.
No you don't. Conceivably you know how to use a debugger; that is not the same thing. As for the many methods, poor baby. You want to build your own service libraries for every project you udnertake? Good luck to you. If you feel like being productive sometime this century, you'l stop making excuses and start learning how to use an unfamiliar API.
quote:Lets look at it this way, I made a line of code comparing the value of a txtbox and a lbl, how was I supposed to know you are supposed to put val(etc.text) there? To my view a number is a number is a number, didn't know that therwise it simply compares them to see which string is bigger.
You are supposed to know that by checking the documentation to see whether it's a string or an int, and not make excuses. Nobody is interested in your excuses. We're willing to help you if you show some slightest hint of a good attitude. You're not doing that.
Posts: 10645 | Registered: Jul 2004
| IP: Logged |
quote:I made a line of code comparing the value of a txtbox and a lbl, how was I supposed to know you are supposed to put val(etc.text) there?
You could always read the documentation. Or think for a second.
I mean, seriously, give some thought to the underlying reasons a method works. When you return txtbox.Value, what sort of data CAN that be? Why?
You're just trying to plug together a bunch of random pieces according to what your teacher tells you; you aren't actually learning anything about the pieces, or why they work together.
Do you know what an index is yet?
Posts: 37449 | Registered: May 1999
| IP: Logged |
Blayne Bradley
unregistered
posted
I know what an index is, when did I say I didn't?
code:
Index Name Price Quantity 0 Halo 3 79$ 50 1 Resistence 79$ 50 2 Smash Bros 79$ 50
My problem is that while itll delete the middle 2 rows if there's a fourth, it wont delete rows 1 and 2, because the dt got merged when i deleted the first row.
code:
Index Name Price Quantity 0 Halo 3 79$ 50 1 Smash Bros 79$ 50
So when it goes to look for row 2, its not there anymore.
IP: Logged |
quote:Originally posted by Blayne Bradley: All I wanted to know is what was wrong with that line of code because as far as I can tell with the debugger everything is fine, I dont know what parameter index relates to, there is no variable called index. All I wanted was what is wrong and what I could do to fix it not the friggin secret of life.
posted
And by the way, if you'd put a moment's thought into this, you'd have realised you can work around the problem by deleting in the opposite order. Took me three seconds to think of.
Posts: 10645 | Registered: Jul 2004
| IP: Logged |
quote:Lets look at it this way, I made a line of code comparing the value of a txtbox and a lbl, how was I supposed to know you are supposed to put val(etc.text) there? To my view a number is a number is a number, didn't know that therwise it simply compares them to see which string is bigger.
You are supposed to know that by checking the documentation to see whether it's a string or an int, and not make excuses. Nobody is interested in your excuses. We're willing to help you if you show some slightest hint of a good attitude. You're not doing that.
This kind of thing is one of the reasons that I think that introductory classes ought to start in assembly and work up from there. Although I'll admit that I might be biased here since this was how I learned programming, I really do believe that it is a great way to learn programming. When you start off really low level, you have to actually consider how all of the data is actually represented in the registers you are working with. Once you get this, it is really easy and intuitive to move on to things like data types and pointers. So even though most programmers are never going to actually use assembly professionally, I think that it helps to create the sort of mindset that makes it easy to understand what is actually going on with the programs you write so that issues like this can be avoided.
Posts: 2437 | Registered: Apr 2005
| IP: Logged |
posted
I believe that concept is key for being succesful at anything. I, for one, have a real hard time learning how to use a tool if I cannot understand the how and why.
Posts: 369 | Registered: Apr 2007
| IP: Logged |
Blayne Bradley
unregistered
posted
Alright, despite being told that he'ld accept it as it was (deleting 1 row at a time) I as it turns out misunderestimated my own stubburnness so I kept at it.
And voila.
code:
For Each GridViewRow1 As GridViewRow In GridView1.Rows '---Look at each checkbox here CheckBox1 = CType(GridViewRow1.FindControl("chkSelector"), CheckBox)
If CheckBox1.Checked Then 'chkBox = True
'Dim ProductID As String = GridView1.DataKeys(GridViewRow1.RowIndex)("pr_code").ToString '---Get the database id KeyId = GridViewRow1.RowIndex 'KeyId = CType(GridView1.DataKeys.Item(GridViewRow1.RowIndex).Value, Int32) '---Use the KeytId to delete from the database.
If KeyId = gt.Rows.Count Then gt.Rows(KeyId - 1).Delete() ' Larry said its okay to delete one row at a time for now. Iff there's time fix it. ElseIf KeyId >= gt.Rows.Count Then gt.Rows(KeyId - KeyId).Delete() Else gt.Rows(KeyId).Delete() ' Larry said its okay to delete one row at a time for now. Iff there's time fix it.
End If End If
Next GridView1.DataSource = gt GridView1.DataBind()
I compensated logically for the rows being shunted off to hammer space and it works for anysize datatable for deleting in any possible combination. In a way that wasn't findable with google, you can try to google it, it is 100% mine.
IP: Logged |
Blayne Bradley
unregistered
posted
Oh and ignore the Larry comment, he wrote in that before I fixed the code to finally work.
IP: Logged |
Unless there's some weird overloading going on, I think you're doing some rather unnecessary arithemtic.
Also, does the meaning of = change from assignment to comparison depending on context in VB? If not, I'm somewhat confused by the If KeyId = gt.Rows.Count line, and if it does, I'm confused by the line after.
Posts: 15770 | Registered: Dec 2001
| IP: Logged |
posted
Also, you follow an "If KeyId = gt.Rows.Count" with an "ElseIf KeyId >= gt.Rows.Count". The '=' in '>=' is superfluous. Just a '>' would do.
Also, have you tested this with a table that has more than a few rows? I'd test at least five rows, with a test run that deletes rows 1,3,5, another run with 1,2,3 and another run with 3,4,5. I don't know VB well enough to say for sure, but I think this is still going to break for more than a few simple 2 or 3-row tests you may have done.
Posts: 3275 | Registered: May 2007
| IP: Logged |
Simple logic game, how do you take two objects - let's say the second and the fifth from the left - out of a line up such that at the time you take them out, they will still be the second and the fifth from the left, respectively?
Posts: 10177 | Registered: Apr 2001
| IP: Logged |
posted
Yeah. It won't crash anymore, but it's going to delete the wrong rows in most non-trivial cases.
Posts: 3275 | Registered: May 2007
| IP: Logged |
Blayne Bradley
unregistered
posted
I've tested it in the following samples.
1 row
3 row
5 row
and random number > 5 rows.
it delets 1 row at a time.
it can delete multiple rows at a time between rows.
and it can delete last 2+ rows at a time without problem.
and it has deleted "all" rows without problem trying differering number of rows (1,3,5,10)
all with unique values like below
code:
0 Halo3 79.99 1 COH 89.99 2 NWN2 79/999
to make sure I know whats being deleted without confusion.
quote:Simple logic game, how do you take two objects - let's say the second and the fifth from the left - out of a line up such that at the time you take them out, they will still be the second and the fifth from the left, respectively?
You take them at the exact same time?
Tristan, who has absolutely no idea what he's talking about.
Posts: 896 | Registered: Feb 2001
| IP: Logged |
posted
Tristan, Sorry, didn't specify. You can only take one at a time. edit: Yes, the answer is really easy. There's no real trick to it.
Blayne, Hey, if you're happy with it, I don't really care anymore. But it's wrong, and obviously so.
Posts: 10177 | Registered: Apr 2001
| IP: Logged |
posted
The thing is, if it *were* working correctly, you'd never need these lines:
code:
If KeyId = gt.Rows.Count Then gt.Rows(KeyId - 1).Delete() ElseIf KeyId >= gt.Rows.Count Then gt.Rows(KeyId - KeyId).Delete()
Their entire purpose is to catch the case when your index has gone past the end of the list. Just saying that you'll delete the last item whenever your index value gets too high is sloppy and dangerous. If your index value does not correspond to an existing row, you should find out why that is happening and fix it.
*EDIT: Eww. It's worse than that. When you go too far (>=) beyond the end, it deletes KeyId-KeyId, or 0. So, in the case where index says 5 but you only have 3 rows, it will delete your first row.
As long as your code doesn't work without that if/else construct, it's not right.
Posts: 3275 | Registered: May 2007
| IP: Logged |
posted
Hmm, let's see. I suppose you could assign each item a designation, e.g. a, b, c, d, and e and then specify that you take b and e out of the line-up.
Or you could have an underlying logic that when you you want to take out X and Y it goes something like: take out X; if X < Y, take out Y-1, if X > than Y, take out Y.
posted
KOM already provided the right answer, and quite explicitly. Don't iterate from row 1 to row 3. Iterate from row 3 to row 1.
Posts: 3275 | Registered: May 2007
| IP: Logged |
posted
Blayne, I wouldn't expect that to work. If it works, it works only because gt.Rows.Delete() has been modified to also delete the GridView's row at the same time.
KoM gave you the obvious solution to your problem.
Posts: 37449 | Registered: May 1999
| IP: Logged |
posted
Tristan, A much simpler rule is, if you need to preserve ordering at the time of removal from the left, start taking things out from the right, i.e. take the fifth from the left first, then the second from the left.
Posts: 10177 | Registered: Apr 2001
| IP: Logged |
Blayne Bradley
unregistered
posted
I thouroughly tested it through the debugger and through run time and everything works just fine, I didn't modify Delete, nor does it delete GridView ros at the same time, Gridview is refreshed and fills its rows based on the new datatable until there's no datatable left thus no gridview.
Its works fine, no errors, everything is where they should be.
IP: Logged |
posted
Uh, that was to MrSquicky. If you do it like Blayne, it's a splendid victory for thousands of years of ingrained western thought-patterns.
Posts: 896 | Registered: Feb 2001
| IP: Logged |
quote:Gridview is refreshed and fills its rows based on the new datatable until there's no datatable left thus no gridview.
Then why do you ever need to check that the index is not greater than the number of rows?
Blayne, think about it. You are telling it to delete the last row whenever the index is equal to the number of rows. Why is the index off by one at that point? If it's off by one then, what's to prevent it from being off by two, three, or ten by the time you've deleted several more rows?
Also, you are telling it to delete the first row whenever the index is greater than the number of rows. How does that ever make sense?
Thus there is no more index(4) thus when i tried to loop through and went to the last row (in this case 4) to delete it, there was no row and it blew up.
Say I havr 5 rows, and I want to dlete all of them.
It will successfully delete all of the rows until the last row which through merging has become row 0.
Thus if I have 10 rows, have KeyId - KeyId and delete that row.
Thus because there is only ONE row left I automatically delete the first row being the only one.
This was the case of having alot of rows to start off with and deleting all of them.
I go back by 1 only when I am deleting a comparitevly small number of rows that are the end rows.
My solution DOES in FACT work, I have thoroughly tested it, and it works, if you think it doesn't or shouldn't work then welcome to Ornery You are Wrong.
IP: Logged |
posted
No, Blayne, your solution doesn't work. The operations that Tom provided will show this to you.
Posts: 10177 | Registered: Apr 2001
| IP: Logged |