I am currently working on a project of "interpreting" C# into VB. The project involves adding images to a database, retrieving images from the database and presenting them in thumbnails.
Right now I have the following Public Class with the Variable that needs to be assigned:
VB:
Imports System.Data
Imports System.Drawing
Imports System.IO
Partial Public Class ThumbFromID
Inherits System.Web.UI.Page
'*** instances
' constants used to create URLs to this page
Public Const PAGE_NAME As String = "ThumbFromID.aspx"
' the image primary key for use when getting image data from database
Public Const IMAGE_ID As String = "img_pk"
' height of the thumbnail created from the original image
Protected THUMBNAIL_SIZE As Integer
' true if using thumbnail THUMBNAIL_SIZE for height, else it is used for width
Protected USE_SIZE_FOR_HEIGHT As Boolean
'*/End Instances
The C# Equivilant is:
public partial class ThumbFromID : System.Web.UI.Page
{
#region Instance Fields// constants used to create URLs to this pagepublic const String PAGE_NAME = "ThumbFromID.aspx";
//the image primary key for use when getting image data from databasepublic const String IMAGE_ID = "img_pk";
// height of the thumbnail created from the original imagepublic static int THUMBNAIL_SIZE;
// true if using thumbnail THUMBNAIL_SIZE for height, else it is used
// for widthpublic static bool USE_SIZE_FOR_HEIGHT;
#endregion
In the default.aspx.vb code page I am trying to access the THUMBNAIL_SIZE variable. My logic tells me that all I would have to do is call it like this: ThumbFromID.THUMBNAIL_SIZE = "value", and indeed that works in C#.
How do I do this in VB? The page is not recoginizing ThumbFromID as a public class...
Here is the C# code that works:
public partial class _Default : System.Web.UI.Page
{
#region instance fields//instance fieldsprotected System.Web.UI.WebControls.Image imgImage;
private int THUMBNAIL_SIZE = 60;
#endregion
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// Creates an image, by querying the SQL database with the given img_pk
/// parameter. The query will return a byte[] array, which represents the
/// image. This byte[] array is then converted into an image and added to
/// the placeholder control "plImage" which is on this page
/// </summary>
/// <param name="img_pk">The primary key to fetch the image data for</param>private void createImageFromDBBytes(int img_pk)
{
ThumbFromID.THUMBNAIL_SIZE = this.THUMBNAIL_SIZE; /// -----> this is does not work for vb
ThumbFromID.USE_SIZE_FOR_HEIGHT = false; /// -----> how do we call this variable from the Partial Public Class?
imgImage = new System.Web.UI.WebControls.Image();
// set the source to the page that generates the thumbnail image
imgImage.ImageUrl = ThumbFromID.PAGE_NAME + "?" +
ThumbFromID.IMAGE_ID + "=" + img_pk;
litException.Visible = false;
plImage.Controls.Clear();
plImage.Controls.Add(imgImage);
}
I don't understand the logic between what the article describes and what I am trying to accomplish...
According to the article my code would look like this:
Imports System.Data
Imports System.IO
Imports System.Drawing
Partial Public Class Admin_Default
Inherits System.Web.UI.Page
'*** declaring instances
Protected imgImage As Image
Private thumnail_size As Integer = 60
'*/End instances
Private Sub createImageFromDBBytes(ByVal img_pk As Integer, ByVal THUMBNAIL_SIZE As Integer, ByVal USE_SIZE_FOR_HEIGHT As Boolean) '***Not Correct***
THUMBNAIL_SIZE = Me.thumnail_size
USE_SIZE_FOR_HEIGHT = False
'\\more code
End Sub
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Try
Dim imgContentType As String = UploadFile.PostedFile.ContentType
If imgContentType.ToLower.StartsWith("image") Then
Dim b As Drawing.Bitmap = Drawing.Image.FromStream(UploadFile.PostedFile.InputStream)
Dim img_pk As Integer = 0
Dim rowsaffected = dbAccess.SaveImageToDB(img_pk, BmpToBytes(b))
If rowsaffected > 0 Then
createImageFromDBBytes(img_pk) '***------> Here is where I am calling the sub and sending the variable
Else
litException.Text = "<br /><p>Error Saving File!</p>"End If
Else
litException.Text = "<br /><p>The file is not an image</p>"End If
Catch ex As Exception
litException.Text = "<br /><p>" & ex.Message & "</p>"End Try
End Sub
End Class
If I am again declaring the variables while passing them into the sub routine, how are the variables changing globally?
This is not a solution... In order for this to work the variables have to be passed into the sub routine. The subroutine that is passing the variable img_pk is being called by a subroutine from the same page class (Default) and not the ThumbFromID class.
So I ask again, How can I access the public variables that are located in the partial public class from other page classes?
Something to this logical effect (but for vb): The_Class.The_Variable
eh... the answer by asifchouhan is not really the answer to the question.
asifchouhan
Here's a class that could be added to a project in VB 2005...
he's actually looking for a solution to access public static/const variables among different web pages, not different classes. allow me to explain:
hrdfsique
In the default.aspx.vb code page I am trying to access the THUMBNAIL_SIZE variable. My logic tells me that all I would have to do is call it like this: ThumbFromID.THUMBNAIL_SIZE = "value", and indeed that works in C#.
hrdfsique, the key part here is not that you're trying to access the data from a different "partial" class... its that you're trying to access the data from a different web page's server side code. if you merely wanted to access data from a different partial
class, you wouldn't even have posted this topic because you would've had no problems to do so (see your words that i'm quoting). unfortunately the fact that asp webpages have those partial classes is confusing, because in this case they won't act as you'd
hope. you mentioned this works in C#? it doesn't. i tried to get it working in C# just now and got nowhere. like me, you'll have to store those const values in a normal class in your App_Code folder instead. here's a detailed explanation i got from this link:
and the important parts that were mentioned: (especially the bolded text)
"ASP.Net Pages have 2 components which never meet... The client-side HTML and the server-side Class. They only SEEM to be connected...
...the server-side elements of these pages will never be able to see each other...
...On the client, the 2 pages (client-side HTML) exist in the same frameset...
...The only way to have these pages communicate is on the client-side, via
JavaScript. So, you will need to use JavaScript to access the HTML objects
in one page from the other page...
so that was the result i came across today (i had the same scenario as you did, only i tried to do it with C#). unless someone knows a wonderful way of getting the info, we're unfortunately limited to only the current web page's class and the App_Code classes.
only one life
it'll soon be past
only what's done for Christ will last
hrdfsique
Member
31 Points
36 Posts
Accessing Variables in Partial Public Class
Apr 10, 2009 11:06 PM|LINK
I am currently working on a project of "interpreting" C# into VB. The project involves adding images to a database, retrieving images from the database and presenting them in thumbnails.
Right now I have the following Public Class with the Variable that needs to be assigned:
VB:
Imports System.Data Imports System.Drawing Imports System.IO Partial Public Class ThumbFromID Inherits System.Web.UI.Page '*** instances ' constants used to create URLs to this page Public Const PAGE_NAME As String = "ThumbFromID.aspx" ' the image primary key for use when getting image data from database Public Const IMAGE_ID As String = "img_pk" ' height of the thumbnail created from the original image Protected THUMBNAIL_SIZE As Integer ' true if using thumbnail THUMBNAIL_SIZE for height, else it is used for width Protected USE_SIZE_FOR_HEIGHT As Boolean '*/End InstancesThe C# Equivilant is:
In the default.aspx.vb code page I am trying to access the THUMBNAIL_SIZE variable. My logic tells me that all I would have to do is call it like this: ThumbFromID.THUMBNAIL_SIZE = "value", and indeed that works in C#.
How do I do this in VB? The page is not recoginizing ThumbFromID as a public class...
Here is the C# code that works:
Your help will be greatly appreciated.partial public class
hrdfsique
Member
31 Points
36 Posts
Re: Accessing Variables in Partial Public Class
Apr 11, 2009 04:29 PM|LINK
Is the above not clear enough or does nobody know how to do this?
C'mon, I know there is someone that can help with this... I am just a beginner, there has got to be hope...
Just to be clear: How can I access the Partial Public Class ThumbFromID - and the variable THUMBNAIL_SIZE from the page class Default.aspx(.vb)?
asifchouhan
Participant
1637 Points
298 Posts
Re: Accessing Variables in Partial Public Class
Apr 11, 2009 04:48 PM|LINK
view this blog
http://www.devx.com/dotnet/Article/22603
U need to create the object of the first class first and then acces the variable value from that object
or
C# you should add the keyword global along with a namespace alias qualifier :: as in the following syntax
global::System.Double mydouble;
Above one is used for the fields or variables
Regards
Asif
Please remember to click “Mark as Answer” on the post that helps you.
This can be beneficial to other community members reading the thread.
This can be beneficial to other community members reading the thread.
hrdfsique
Member
31 Points
36 Posts
Article 22603 Does not give a solution for this problem.
Apr 13, 2009 05:52 PM|LINK
I don't understand the logic between what the article describes and what I am trying to accomplish...
According to the article my code would look like this:
Imports System.Data Imports System.IO Imports System.Drawing Partial Public Class Admin_Default Inherits System.Web.UI.Page '*** declaring instances Protected imgImage As Image Private thumnail_size As Integer = 60 '*/End instances Private Sub createImageFromDBBytes(ByVal img_pk As Integer, ByVal THUMBNAIL_SIZE As Integer, ByVal USE_SIZE_FOR_HEIGHT As Boolean) '***Not Correct*** THUMBNAIL_SIZE = Me.thumnail_size USE_SIZE_FOR_HEIGHT = False '\\more code End SubIf I am again declaring the variables while passing them into the sub routine, how are the variables changing globally?
This is not a solution... In order for this to work the variables have to be passed into the sub routine. The subroutine that is passing the variable img_pk is being called by a subroutine from the same page class (Default) and not the ThumbFromID class.
So I ask again, How can I access the public variables that are located in the partial public class from other page classes?
Something to this logical effect (but for vb): The_Class.The_Variable
hrdfsique
Member
31 Points
36 Posts
Re: Article 22603 Does not give a solution for this problem.
Apr 15, 2009 10:45 PM|LINK
I can't believe no one knows how to use partial public classes in vb!!!
asifchouhan
Participant
1637 Points
298 Posts
Re: Article 22603 Does not give a solution for this problem.
Apr 17, 2009 10:03 AM|LINK
Just have a look at this code
Here's a class that could be added to a project in VB 2005.
Public Class CombinedClass
Private m_Property1 As String
Public Sub New(ByVal Value As String)
m_Property1 = Value
End Sub
Public Sub Method1()
MessageBox.Show(m_Property1)
End Sub
Property Property1() As String
Get
Return m_Property1
End Get
Set(ByVal value As String)
m_Property1 = value
End Set
End Property
End Class
This class can be called (for example, in the Click event code for a Button object) with the code:
Dim ClassInstance As New _
PartialClass("About Visual Basic Partial Classes")
ClassInstance.Method1()
I hope u are trying to do this
If you need more explanations go through this link
http://visualbasic.about.com/od/usingvbnet/a/partialclasses.htm
Regards
Asif
If you like my post.Mark it as "ANSWER"
This can be beneficial to other community members reading the thread.
wRatte
Member
8 Points
8 Posts
Re: Article 22603 Does not give a solution for this problem.
Aug 05, 2009 03:48 PM|LINK
eh... the answer by asifchouhan is not really the answer to the question.
he's actually looking for a solution to access public static/const variables among different web pages, not different classes. allow me to explain:
hrdfsique, the key part here is not that you're trying to access the data from a different "partial" class... its that you're trying to access the data from a different web page's server side code. if you merely wanted to access data from a different partial class, you wouldn't even have posted this topic because you would've had no problems to do so (see your words that i'm quoting). unfortunately the fact that asp webpages have those partial classes is confusing, because in this case they won't act as you'd hope. you mentioned this works in C#? it doesn't. i tried to get it working in C# just now and got nowhere. like me, you'll have to store those const values in a normal class in your App_Code folder instead. here's a detailed explanation i got from this link:
http://www.justskins.com/forums/accessing-variables-of-another-class-85933.html
and the important parts that were mentioned: (especially the bolded text)
so that was the result i came across today (i had the same scenario as you did, only i tried to do it with C#). unless someone knows a wonderful way of getting the info, we're unfortunately limited to only the current web page's class and the App_Code classes.
it'll soon be past
only what's done for Christ will last