Print Page | Close Window

Change class instance

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=6929
Printed Date: 29 March 2026 at 10:49am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Change class instance
Posted By: Boecky
Subject: Change class instance
Date 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?




Replies:
Posted By: Diep-Vriezer
Date 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



-------------
Gone..


Posted By: Diep-Vriezer
Date 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..


Posted By: Boecky
Date 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


Posted By: Bunce
Date 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.


Posted By: Boecky
Date 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


Posted By: Diep-Vriezer
Date Posted: 10 November 2003 at 10:19am

 VS.NET compiles it all into one right?



-------------
Gone..


Posted By: MorningZ
Date 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


Posted By: Boecky
Date Posted: 10 November 2003 at 10:31am

yes and no
Everything will be compiled to 1 dll. In my class I have the following member variables:
m_strWelcome = "Welcome"
m_strHello = "Hello"

And also exactly the same variables but then with another language.

Is it possible to separate this and put the variables in another dll for each language?



Posted By: Diep-Vriezer
Date Posted: 10 November 2003 at 11:49am

To MoringZ

It isn't compiled into one? That's quite sad, since that was the entire idea right? Multiple languages in one project. Can't you start a 'blank' project (not a solution) and then make both C# and Vb.Net?



-------------
Gone..


Posted By: MorningZ
Date Posted: 10 November 2003 at 11:57am

i ran into the same problem before, http://www.crystaltech.com/forum/topic.asp?TOPIC_ID=6212&FORUM_ID=16&CAT_ID=2&Topic_Title=what+do+i+need+to+do+to+expose+a+class%3F&Forum_Title=%2ENET+Forum - and here was the solution (same as i said above)

remember that when you start a new project, you are choosing "C#" or "VB.NET" as the base, and then going from there, so not having pages of both flavors in the same project makes perfect sense



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Diep-Vriezer
Date Posted: 10 November 2003 at 12:21pm
Have you tried 'Empty project'? I'm going to try it right now.

-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 10 November 2003 at 12:23pm

Hmpf, stupid studio. You're right..

It just can't be done, that's right. You'll have to create seperate projects, within the same solution... Weird studio.



-------------
Gone..


Posted By: MorningZ
Date Posted: 10 November 2003 at 12:46pm

not sure where you think its "stupid" or "weird".. its doing exactly what you tell it to do



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Diep-Vriezer
Date Posted: 10 November 2003 at 3:12pm

Yeah m8, i know, it's just that they've been advertising and telling everyone that you can have TONS of languages within a application, and now it turns out that it needs to have seperate projects.

Quite logic actually, but still, this might be ONE of the improvements to the next VS.NET

BTW: is that your windows? What a messed up colors



-------------
Gone..


Posted By: MorningZ
Date Posted: 10 November 2003 at 3:30pm

but see, you dont understand the difference between an "application" and a "project"

there can (and typically may be) many "projects" in an application, that's where it al ties in....

as for my colors, i saved the image in a lower resolution so people didnt have to download a several hundred kb image off my server, as long as you got the point of the screenshot is all that matters



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Boecky
Date Posted: 11 November 2003 at 2:00am
Yeah, and every separate project in a solution can be compiled to an execute or a dll



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net