Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Change class instance
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Change class instance

 Post Reply Post Reply Page  123>
Author
Boecky View Drop Down
Groupie
Groupie
Avatar

Joined: 23 December 2002
Location: Belgium
Status: Offline
Points: 110
Post Options Post Options   Thanks (0) Thanks(0)   Quote Boecky Quote  Post ReplyReply Direct Link To This Post Topic: Change class instance
    Posted: 02 November 2003 at 2:48pm

hey,

I try to put some text that I get out a property of a class into a label. That's no problem. But I have 2 exactly the same classes but the text in it is different (translation). My question is, how I can change the instance of the class (I don't know how to explain).

This works:

Dim id As Integer
id = Request.QueryString("id")

If id = 1 Then
Dim lang As Dutch
lang = New Dutch()
Label1.Text = lang.Welcome
End If

But I want something like this:

Dim id As Integer
id = Request.QueryString("id")

If id = 1 Then
Dim lang As Dutch
lang = New Dutch()
End If

If id = 2 Then
Dim lang As English
lang = New English()
End If

Label1.Text = lang.Welcome

What I want is that I can use the same label.text = lang.welcome for every class, that I don't have to type this in every if..then statement. Does anyone have some suggestions?

Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 02 November 2003 at 3:03pm

Yes, something like this should work

Dim id As String = Request.QueryString("lang")

If id = "1" Then

 Dim lang As New Dutch()

ElseIf id = "2" Then

 Dim lang As New English()

End If

lblHeader.Text = lang.lblHeaderText.ToString



Edited by Diep-Vriezer
Gone..
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 02 November 2003 at 3:05pm

No wait, that won't work, since the Dim statement is in the If tag.

Try this:

Dim id As String = Request.QueryString("lang")

If id = "1" Then

 Dim lang As New Dutch()
 lblHeader.Text = lang.lblHeaderText

ElseIf id = "2" Then

 Dim lang As New English()
 lblHeader.Text = lang.lblHeaderText

End If

Gone..
Back to Top
Boecky View Drop Down
Groupie
Groupie
Avatar

Joined: 23 December 2002
Location: Belgium
Status: Offline
Points: 110
Post Options Post Options   Thanks (0) Thanks(0)   Quote Boecky Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2003 at 2:04am
Yes this will work, but then I have to put the lblHeader.Text = lang.lblHeaderText and all other objects that need text from the class in the if statement. What I want is to make something that declare the correct object (Dim lang As New Dutch()) depending on which id you have. And using the same lblHeader.Text = lang.lblHeaderText things out of the if statement for every class. I don't know that you get what I mean
Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2003 at 2:52am

I'd be choosing your languages at a different level than in your page.

At the very least, something like this:

dim lang as new language("English")

lblHeader.Text = lang.lblHeaderText

In your Language class, you store you're properties depending on the language chosen in your constructor.

Your UI really shouldn't be doing this kind of comparison IMO.

Cheers,
Andrew

There have been many, many posts made throughout the world...
This was one of them.
Back to Top
Boecky View Drop Down
Groupie
Groupie
Avatar

Joined: 23 December 2002
Location: Belgium
Status: Offline
Points: 110
Post Options Post Options   Thanks (0) Thanks(0)   Quote Boecky Quote  Post ReplyReply Direct Link To This Post Posted: 10 November 2003 at 8:58am
yeah, this seems te best solution...I made something like this now and it works fine. But now every language is in one class (dll). I have to find out how I can put every language in a separate dll. Suggestions are always welcome
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 10 November 2003 at 10:19am

 VS.NET compiles it all into one right?

Gone..
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 10 November 2003 at 10:28am
if your project has C# and VB.NET code, it wont compile it into one, you'll have to have them in seperate projects (but you can have these multiple projects in the same "solution")
Contribute to the working anarchy we fondly call the Internet
Back to Top
 Post Reply Post Reply Page  123>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.