http://calcg.org/newlogo2.png Not Logged in.
Login | Register

General Discussion Board \ Non-Calculator Related World \ Visual Basic

Click here to log in (you must be logged in to post comments).

AuthorComment
haveacalc
Guardian
avatar
Posted: 8 Dec 2005
21:46 GMT
Total Posts: 1111
Who here knows a decent amount about Visual Basic? I have a question: When the name of an object is stored in a string (in this case, let's say string "abc"), how can I use it as a substitute for the specific name of the object?

Example:
Button1 could be the object.
Instead of doing:

Me.Button1.Location = New.System.Drawing.Point(variable1, variable2)

I would like to do:

Me.abc.Location = New System.Drawing.Point(variable1, variable2)

or whatever syntax is needed.

I think it might involve abc.Format( in some way, but I would need the syntax for that as well.

I use Visual Basic.Net 2003, but help from any version would be quite welcome and helpful. Thanks!

[Edited by haveacalc on 09-Dec-05 07:45]

---
-quoted directly from most movies that don't exist (and some that do).
stephendonnelly88
Dragoon
Posted: 9 Dec 2005
07:22 GMT
Total Posts: 97
Ah yes.......I used to be real big into VB (It was Visual Basic 6, at the time).

I dropped Visual Basic, and picked up C++....

Brings back good memories though. :)
haveacalc
Guardian
avatar
Posted: 9 Dec 2005
07:50 GMT
Total Posts: 1111
If the previous post could have been any more pointless, I would have shot myself. By saying that you dropped Visual Basic, you say that you don't know the answer to my question?

[Edited by haveacalc on 09-Dec-05 17:34]

---
-quoted directly from most movies that don't exist (and some that do).
jessef
Goliath
avatar
Posted: 9 Dec 2005
11:44 GMT
Total Posts: 192
can you always expect free advice to be helpful?
haveacalc
Guardian
avatar
Posted: 9 Dec 2005
12:27 GMT
Total Posts: 1111
You can't really call that advice. Maybe an under-detailed flashback. You single-handedly prove your own point. By your post.

Edit by L: Oh, don't be so negative. Only admins and moderators can be negative :)

[Edited by Lunchbox on 10-Dec-05 03:25]

---
-quoted directly from most movies that don't exist (and some that do).
stephendonnelly88
Dragoon
Posted: 9 Dec 2005
13:51 GMT
Total Posts: 97
Why are there so many members in these forums that are so petty? Are your lives so shallow that all you guys (I'm reffering to serveral members here -- not neccessarily just those who've posted within this thread) can do is go around pointing fingers at every imperfection you see?

Start worrying about real issues. I understand that it is not courteous to the mods/admins to post unneccesarily, but believe me: I'm not going to end-up being a postcount-happy spammer. I been there done that.

Of course, I will say no more in this thread so to not annoy the forum-gods (the admins). :)

[Edited by stephendonnelly88 on 09-Dec-05 22:57]
haveacalc
Guardian
avatar
Posted: 9 Dec 2005
14:20 GMT
Total Posts: 1111
If you were talking about me, then:

Actually, I was asking for assistance with part of my final project for a programming class. That's pretty real, isn't it? As for pointing fingers, that's exactly what you're doing. You're not helping. I noticed that you posted and then edited your post, deciding that the first one was not insulting enough (no, I'm not just going by the "edited by stephendonnelly88" message at the bottom). Funny that your first post said "I will say no more", but you still did? There's a difference between imperfection and a completely pointless post. I really wasn't looking at imperfection in your first post as much as being technical with jessef.

If you weren't speaking of me, then never mind.

[Edited by haveacalc on 09-Dec-05 23:25]

---
-quoted directly from most movies that don't exist (and some that do).
CoffmanRunner
Ultralisk
avatar
Posted: 9 Dec 2005
14:47 GMT
Total Posts: 235
I don't know if this helps i Googled it and found this i don't write VB nor have i ever writen VB but here it is I hope it helps

Insert a button, and change the text to Close, or to anything else that would tell a user that this button closes the program. Rename the button, too. Something appropriate could be btnClose. But you can name it whatever you want, like btnthisisthebuttonthatclosestheprogramwhenyouclickit. It's a bit long though and of little use for quick identification. If you rename all your buttons like this, you'll spend more time renaming your buttons than coding a program. Drag the button to an appropriate place. Don't forget to code it so that it closes the program. By the way, you can use the code as we did it in the previous article:

Private Sub btnClose_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnClose.Click

Me.Close()

End Sub

You can do that quicker, too:

Private Sub btnClose_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnClose.Click

End

End Sub



If that's not what you want...

Rename the temporary file by giving the same
'name as deleted random file.
Rename("abcdefg.tnt", TextBox1.Text)

this renames a file but will it work on a button?

If sorry if this doesn't help i tried :)

---
Never gonna let you down...
haveacalc
Guardian
avatar
Posted: 9 Dec 2005
15:19 GMT
Total Posts: 1111
How much time did you spend looking for that? I really appreciate the effort, but that wasn't exactly what I was talking about. When I said "Button1", I was just giving an example of an object that fit the description of what I meant. A lot of objects would fit.

I know all of the basics of Visual Basic and can code quite well (I'm one of the most advanced people in the class), but what I meant was being able to use the value of a string as a substitution for the direct text of an object's name. Yet another example:

Dim stringexample as String

stringexample = "TextBox5"

Instead of:

TextBox5.Text = "abc"

I would like to do something along the lines of this:

stringexample = "abc" and it would change the text of TextBox5.Text to "abc".

I am pretty sure this is possible.
By the way, the game I'm making is Chess.

[Edited by haveacalc on 10-Dec-05 00:36]

---
-quoted directly from most movies that don't exist (and some that do).
CoffmanRunner
Ultralisk
avatar
Posted: 9 Dec 2005
16:12 GMT
Total Posts: 235
ok i talked to my dad and he knew he said to use Addressof so i looked ot up...

VB 5.0 has provided a useful operator called AddressOf which returns the address of a function (there is no such operator in VB 4.0). It may be used only in front of a parameter when you call a function and uses like

FuncP = AddressOf MyFunction

are wrong and cause error. So, you must call EnumWindows like that:

Success& = EnumWindows(AddressOf cbFunc, 58&)

You must also write the callback function. There are different type of callbacks that have a different sets of parameters. Description of this parameter can be found in a SDK Help file or MS SDK documentation. Here is the declaration for the callback:

Public Function cbFunc (ByVal Hwnd As Long, ByVal lParam As Long) as Long

Here is a sample of callbacks:

(paste this code in a module, as callbacks should be Public)

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function EnumWindows Lib "User32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Public Function cbFunc(ByVal Hd As Long, ByVal lParam As Long) As Long
If lParam = 58 Then 'enum windows
Dim St As String
St = Space(255)
Ret& = GetWindowText(Hd, St, Len(St))
Debug.Print Left(St, Ret&)
cbFunc = 1
End If
End Function

(paste the following in a form module with a command button on it)

Private Sub Command1_Click()
Success& = EnumWindows(AddressOf cbFunc, 58&)
End Sub

Note that the function returns 1. If it returns 0, the enumeration will stop. Watch the Immediate Window.

This sample enumerates the captions of all (literally) windows (no childs).

sorce of info... http://www.geocities.com/SiliconValley/Lab/1632/atch10.html


hope that helps! good luck :)

---
Never gonna let you down...
Lunchbox
Carrier
avatar
Posted: 9 Dec 2005
18:30 GMT
Total Posts: 2007
You can dereference variables like this in perl, but that doesn't help in the slightest.
haveacalc
Guardian
avatar
Posted: 12 Dec 2005
15:37 GMT
Total Posts: 1111
Well, I've found a way around that part. So far, I've coded the white rooks, knights, pawns, and I'm almost done with the bishops. It's looking pretty good. I have to finish by the end of the week to get full credith though...

---
-quoted directly from most movies that don't exist (and some that do).
haveacalc
Guardian
avatar
Posted: 12 Dec 2005
16:48 GMT
Total Posts: 1111
Now the bishop's working. It's on to the white queen.

---
-quoted directly from most movies that don't exist (and some that do).
haveacalc
Guardian
avatar
Posted: 13 Dec 2005
17:08 GMT
Total Posts: 1111
Everythings working now, both black and white pieces, except for:
Taking pieces
Check and check-mate
Castling
En passant
Attacking with pawns

I'm almost done.

[Edited by haveacalc on 14-Dec-05 02:08]

---
-quoted directly from most movies that don't exist (and some that do).
Lunchbox
Carrier
avatar
Posted: 13 Dec 2005
17:17 GMT
Total Posts: 2007
Triple posting = bad. Edit button = good.
haveacalc
Guardian
avatar
Posted: 13 Dec 2005
20:16 GMT
Total Posts: 1111
Just updating everyone on the progress of Chess... Didn't know that it counted as triple-posting in that way. By the way, I'm done with the main game! All that's left is:

Detecting check (even now, if you take the king, the game's over)
Castling
En Passant

I know it's not the biggest accomplishment ever, but I still think it's pretty good for only programming in Visual Basic for 4 months. I'll have a download link when it's all done.

---
-quoted directly from most movies that don't exist (and some that do).
CoffmanRunner
Ultralisk
avatar
Posted: 14 Dec 2005
13:35 GMT
Total Posts: 235
Haveacalc - I belive any prgming is good and an accoplishment (with some exceptions) i want to learn java and my dad want's to get me into c# as do i and i would be glad to try out your game after you finish!

---
Never gonna let you down...
haveacalc
Guardian
avatar
Posted: 14 Dec 2005
19:41 GMT
Total Posts: 1111
Wow. Chess isn't as hard to make as it is time-consuming! I've spent a week doing it. Both kings are able to castle on either side. I've gotten pawns that have reached the other side of the board to turn into queens (yes, I know they could be bishops, knights, or rooks as well, but queens are best and save time). It's all fully-funcional with no glitches that I know of. The final version may be <a href="http://www.ucomics.com/foxtrot/" target="_blank"">foxtrot</a> oriented, but it's getting finished quickly.

Edit: Almost done. Nothing left but "en passant".

[Edited by haveacalc on 16-Dec-05 23:31]

---
-quoted directly from most movies that don't exist (and some that do).
haveacalc
Guardian
avatar
Posted: 17 Dec 2005
16:42 GMT
Total Posts: 1111
DONE! I posted a link to it earlier today, but I did en passant wrong and fixed it. Here is the real version: http://www.geocities.com/plipperson/Chess.zip

One thing, though. It doesn't automatically detect check, which makes it stealthly and hardcore : ). You win by taking the opponent's king.

Please post any bugs you find. I currently know of none.

---
-quoted directly from most movies that don't exist (and some that do).
CoffmanRunner
Ultralisk
avatar
Posted: 17 Dec 2005
17:18 GMT
Total Posts: 235
pretty cool! a few thing you may wnat to add a menu bar and the pictures of each piece could use some work and the is no AI (i know AI is very hard to write!)

---
Never gonna let you down...
haveacalc
Guardian
avatar
Posted: 17 Dec 2005
17:24 GMT
Total Posts: 1111
The reason that the pictures are blurry is that I drew 8x8 pictures, but I had to stretch it to 24x24. If that's what you're talking about, it could be fixed easily. Is it?

[Edited by haveacalc on 18-Dec-05 22:55]

---
-quoted directly from most movies that don't exist (and some that do).
haveacalc
Guardian
avatar
Posted: 28 Dec 2005
14:11 GMT
Total Posts: 1111
I just realized I did en passant wrong. Gonna have to redo that...

12/28/05- Done! The link's been updated.
http://www.geocities.com/plipperson/Chess.zip
En passant has been corrected.


---
-quoted directly from most movies that don't exist (and some that do).





Portal | My Account | Register | Lost Password or Username | TOS | Disclaimer | Help | Site Search | File Archives Copyright © 2002-2019 CalcG.org