Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Anyone code in VB.NET?

Thread Tools
 
Search this Thread
 
Old 19 August 2008, 05:28 PM
  #1  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default Anyone code in VB.NET?

I've been using VB6 until recently as saw no benefit in attempting to move existing projects over.

However, I am now on a new one and we need to use a supplied .NET component, so I'm now forced into getting used to VB.NET

I have a probably stupid problem (if you know .net) but I have a sub in a form module which references a button. For the sake of arguement let's say the sub is passed "strText", and a button id and it sets this buttons text as strText. So I have:

Code:
Public Sub CreateMapButton(ByVal strText As String, ByVal buttonid As Integer)

Dim theButton As Button

Diagnostics.Debug.Print("Creating button """ & strText & """ (buttonid=" & buttonid & ")

If buttonid = 1 Then
  theButton = butMap1
elseif. buttonid......


End If

theButton.Text = strText
theButton.Visible = True
Diagnostics.Debug.Print("Finished creating button")

End Sub
if I call this from another button in the form:

Code:
CreateMapButton("Test button", 1)
Then sure enough the text is set on the first button and the debug printout is as expected.

Now I have a function in another module which loads up a list of texts for said buttons from the database and then calls the sub above for each one. This prints the debug out as expected, but the button caption never changes.

This would work fine in vb6 (although yes I know the if - then - blahh to set the button control is a bit rubbish, this is only a lightweight in-house app).

Why is .NET being an **** and not changing the button properties when the sub is called from a proceedure which is external to the form?

TIA,

Andy

Last edited by SiDHEaD; 21 August 2008 at 01:19 PM.
Old 19 August 2008, 08:45 PM
  #2  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Default

have you tried specifying formname.buttonname?

or email me an example project and Ill take a look.

David
Old 19 August 2008, 11:51 PM
  #3  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default

Yes i tried that, didnt work either.

I'll pack it up and send it over in the morning.

Cheers!
Old 20 August 2008, 12:04 AM
  #4  
Fabioso
Scooby Regular
 
Fabioso's Avatar
 
Join Date: Jun 2005
Posts: 1,130
Likes: 0
Received 0 Likes on 0 Posts
Default

Crikey I didn't realise people still use VB6................dot Net has been around like at least half a decade..........
Old 20 August 2008, 09:45 AM
  #5  
Dracoro
Scooby Regular
 
Dracoro's Avatar
 
Join Date: Sep 2001
Location: A powerslide near you
Posts: 10,261
Likes: 0
Received 0 Likes on 0 Posts
Default

We still use VB, however our apps are being re-written in .NET (mainly C# rather than VB.net though).

Anyway, for many software houses, it simply may not be cost effective to port to .NET without serious financing. If it ain't broke, don't fix it etc. Bit like running an old car, plenty do it.
Old 20 August 2008, 02:34 PM
  #6  
AllenJ
Scooby Regular
 
AllenJ's Avatar
 
Join Date: Mar 2004
Posts: 752
Likes: 0
Received 0 Likes on 0 Posts
Default

When you say another module, I take it you mean another class, if so,
reference the called class in the calling class to expose the function, create an instance of the class if it's not static and you should be good to go.

Coming from a VB 5.0/6.0 and Delphi background myself, i can well assure you, 6 years into .NET, it rocks.

If this is not helpful, please send me your code and I'll have a look. I'm off to Prague tomorrow so i may not check it till weekend.

Good luck
Old 21 August 2008, 01:23 PM
  #7  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default

Just making a quick little test app to send and i notice 2 warnings which will hopefully make more sense to someone who knows what they are doing. Such a pain, VB6 was great for just knocking up apps for at work!!
Old 21 August 2008, 01:26 PM
  #8  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default

Here is a cut down example (the proper one does more stuff to the button, theres more buttons, and its database driven).

http://www.sidtech.co.uk/andy/TempTest.zip
Old 26 August 2008, 12:48 AM
  #9  
AllenJ
Scooby Regular
 
AllenJ's Avatar
 
Join Date: Mar 2004
Posts: 752
Likes: 0
Received 0 Likes on 0 Posts
Default

I'll have a look in the morning
Old 26 August 2008, 01:02 AM
  #10  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default

Thanks! I'm at a bit of a loss, it just behaves so differently to VB6 in some respects (such as this hehe).

Much appreciated!
Old 26 August 2008, 01:37 AM
  #11  
AllenJ
Scooby Regular
 
AllenJ's Avatar
 
Join Date: Mar 2004
Posts: 752
Likes: 0
Received 0 Likes on 0 Posts
Default

I've loaded the code in .NET and currently checking it out. Are button names built dynamically or is the difference the incremental value ?
Old 26 August 2008, 01:44 AM
  #12  
AllenJ
Scooby Regular
 
AllenJ's Avatar
 
Join Date: Mar 2004
Posts: 752
Likes: 0
Received 0 Likes on 0 Posts
Default

With a little tweak in your code, i got th efollowing messages

Creating button "Test button 1" (buttonid=1)
Finished creating button
Creating button "Test button 2" (buttonid=2)
Finished creating button
Creating button "Test button 3" (buttonid=3)
Finished creating button

Is that what you are after ?
Old 26 August 2008, 09:06 AM
  #13  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default

It should change the text on the button itself. The fact the debug prints out fine is what i dont understand, everything is running through as it should. The button text just never gets changed!! LOL
Old 26 August 2008, 09:07 AM
  #14  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default

The buttons are not dynamically named, mainly as I didnt know that was possible.
Old 26 August 2008, 10:48 AM
  #15  
AllenJ
Scooby Regular
 
AllenJ's Avatar
 
Join Date: Mar 2004
Posts: 752
Likes: 0
Received 0 Likes on 0 Posts
Default

Hi SidHead,

The text will not change until an event has been raised for that control.
If you add the text change command within the butMap1 click event, it will be actioned, to do so from Loadmap event, I think you'll need to raise the event through the use of 'delegate'.

If this has not been resolved by lunch time, let me know and I'll have another play around.

try this link
Event driven programming with Visual Basic .NET « –==PC==–

Another link on raising events

Using Class Events in VB.Net

Hopefully this will help.

Last edited by AllenJ; 26 August 2008 at 10:55 AM.
Old 27 August 2008, 08:44 AM
  #16  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default

I'm having problems. I see where the articles are coming from but I'm struggling to understand how to relate that to my simple bit of code that works in VB 6 - it shouldnt need events raising its just one sub calling another.
Old 27 August 2008, 08:54 AM
  #17  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default

it's ok I've now narrowed it down to being the "Dim frm As New WindowsApplication1.Form1" in the module function. This can be removed fine in my sample one. But remove it in the real one and you cant find the CreateMapButton grrrrrrrr

I think it might be related to me changing the name on the form. I'll have a play.

Thanks
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Darrell@Scoobyworx
Trader Announcements
26
30 January 2024 01:27 PM
Abx
Subaru
22
09 January 2016 05:42 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM
Sam Witwicky
Engine Management and ECU Remapping
17
13 November 2015 10:49 AM



Quick Reply: Anyone code in VB.NET?



All times are GMT +1. The time now is 02:48 AM.