-
Nov 8th, 2017, 10:34 AM
#1
Thread Starter
Don't Panic!
[RESOLVED] VB.Net > ASP - What I thought should work, isn`t
Hi
I need a pointer in the right direction or I think I just wont bother messing with .net.... sigh
Code:
Response.Write("<p>jeito 1</p>")
'assume that the order of the elements is generated properly
'so that there is a 'tree' of elements to build
Dim dOrder As New Stack
Dim objOpenOrder(2000) As clsHtmlElement
Dim aParents(2000) As String
Dim lngWhichNivel As Long
Dim lngOpenOrder As Long
Dim lngOpenCtrl As Long
Dim lngCtrl As Long
Dim sRes As New StringBuilder
lngOpenOrder = 0
lngWhichNivel = 1
cForm.setTheNivel(lngWhichNivel)
objOpenOrder(lngOpenOrder) = cForm
aParents(lngOpenOrder) = ""
lngOpenOrder += 1
lngWhichNivel = 2
cDiv.setTheNivel(lngWhichNivel)
cDiv.setParentHtmlId(cForm.getTheID())
objOpenOrder(lngOpenOrder) = cDiv
lngOpenOrder += 1
lngWhichNivel = 3
cLbl.setTheNivel(lngWhichNivel)
cLbl.setParentHtmlId(cDiv.getTheID())
objOpenOrder(lngOpenOrder) = cLbl
lngOpenOrder += 1
cDiv2.setParentHtmlId(cDiv.getTheID())
cDiv2.setTheNivel(lngWhichNivel)
objOpenOrder(lngOpenOrder) = cDiv2
If lngOpenOrder > 0 Then
lngCtrl = 0
Response.Write(objOpenOrder(lngCtrl).htmlStart())
dOrder.Push(lngCtrl)
For lngCtrl = 1 To lngOpenOrder
If objOpenOrder(lngCtrl).getTheNivel() < objOpenOrder(dOrder.Peek()).getTheNivel() Then
Do While objOpenOrder(lngCtrl).getTheNivel() < objOpenOrder(dOrder.Peek()).getTheNivel()
lngOpenCtrl = dOrder.Pop()
Response.Write(objOpenOrder(lngOpenCtrl).htmlEnd())
Loop
Else
If objOpenOrder(lngCtrl).getTheNivel() = objOpenOrder(dOrder.Peek()).getTheNivel() Then
lngOpenCtrl = dOrder.Pop()
Response.Write(objOpenOrder(lngOpenCtrl).htmlEnd())
End If
End If
If lngCtrl <= lngOpenOrder Then
Response.Write(objOpenOrder(lngCtrl).htmlStart())
dOrder.Push(lngCtrl)
End If
Next
End If
'should be one open class minimum
'any open classes...
lngOpenCtrl = dOrder.Pop()
Response.Write(objOpenOrder(lngOpenCtrl).htmlEnd())
If (lngOpenCtrl > 0) Then
Do Until objOpenOrder(lngOpenCtrl).getTheNivel() <= 1
lngOpenCtrl = dOrder.Pop()
Response.Write(objOpenOrder(lngOpenCtrl).htmlEnd())
Loop
End If
This is a first attempt at using vb.net coming from an MS Access/VBA background with a little experience in VB6. Currently using Java/JSP at work.
I managed to create the base class and use new classes extending that.
But I am trying to hold objects of the classes in an array and I thought if I declared the array of the base class I could use any object based off of it. Apparently not as when running with a debug, and using the immediates window it is returning some weird stuff or using the methods of the base instead of the class. So I have obviously got it all wrong...
So.... what to do?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Nov 8th, 2017, 11:29 AM
#2
Member
Re: VB.Net > ASP - What I thought should work, isn`t
have you tried using a list of <T> (where <T> is your object)?
second place is just the first loser...
-
Nov 8th, 2017, 11:35 AM
#3
Thread Starter
Don't Panic!
Re: VB.Net > ASP - What I thought should work, isn`t
Can I use the base class as T though ?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Nov 8th, 2017, 11:39 AM
#4
Member
Re: VB.Net > ASP - What I thought should work, isn`t
yes in VB its
Code:
dim x as List(of MyObj)
' to get things out
for each y as MyObj in x
y.firstproperty...
next
second place is just the first loser...
-
Nov 9th, 2017, 06:23 AM
#5
Thread Starter
Don't Panic!
Re: VB.Net > ASP - What I thought should work, isn`t
I'll post the code later on, but I updated to use that list dropping in my base class.
Still didn't like it.
I think I'm missing something or perhaps I just need to use Object ?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Nov 9th, 2017, 07:30 AM
#6
Re: VB.Net > ASP - What I thought should work, isn`t
Originally Posted by Ecniv
I'll post the code later on, but I updated to use that list dropping in my base class.
Still didn't like it.
I think I'm missing something or perhaps I just need to use Object ?
You virtually never need to use Object, if you have a base class you are inheriting from have you marked the methods in the base class as Overridable and in the derived classes used the Overrides keyword?
-
Nov 9th, 2017, 10:33 AM
#7
Thread Starter
Don't Panic!
Re: VB.Net > ASP - What I thought should work, isn`t
Code:
Dim dOrder As New Stack
Dim objOpenOrder As New List(Of clsHtmlElement)
Dim aParents(2000) As String
Dim lngWhichNivel As Long
Dim lngOpenOrder As Long
Dim lngOpenCtrl As Long
Dim lngCtrl As Long
Dim sRes As New StringBuilder
lngOpenOrder = 0
lngWhichNivel = 1
cForm.setTheNivel(lngWhichNivel)
objOpenOrder.Add(cForm)
aParents(lngOpenOrder) = ""
lngOpenOrder += 1
lngWhichNivel = 2
cDiv.setTheNivel(lngWhichNivel)
cDiv.setParentHtmlId(cForm.getTheID())
objOpenOrder.Add(cDiv)
Ah hmm ... no and yes.
I use the overrides on the child class...
easier if I post the code for the classes...
Base Class :
Code:
Imports Microsoft.VisualBasic
Public Class clsHtmlElement
Private useVersion As Long
Private lngNivel As Long
Private strTheId As String = ""
Private strTheName As String = ""
Private strTheText As String = ""
Private strTheLink As String = ""
Private strTheTitle As String = ""
Private strTheStyle As String = ""
Private strClassName As String = ""
Private strParentID As String = ""
Public Sub New()
useVersion = 1
End Sub
Public Function getTheNivel() As Long
getTheNivel = lngNivel
End Function
Public Sub setTheNivel(l As Long)
lngNivel = l
End Sub
Public Function getUseVersion() As Long
Return useVersion
End Function
Public Sub setUseVersion(l As Long)
useVersion = l
End Sub
Public Function getTheID() As String
Return strTheId
End Function
Public Sub setTheID(s As String)
strTheId = s
End Sub
Public Function getName() As String
Return strTheName
End Function
Public Sub setName(s As String)
strTheName = s
End Sub
Public Function getText() As String
Return strTheText
End Function
Public Sub setText(s As String)
strTheText = s
End Sub
Public Function getLink() As String
Return strTheLink
End Function
Public Sub setLink(s As String)
strTheLink = s
End Sub
Public Function getClassName() As String
Return strClassName
End Function
Public Sub setClassName(s As String)
strClassName = s
End Sub
Public Function getTheTitle() As String
Return strTheTitle
End Function
Public Sub setTheTitle(s As String)
strTheTitle = s
End Sub
Public Function getTheStyle() As String
Return strTheStyle
End Function
Public Sub setTheStyle(s As String)
strTheStyle = s
End Sub
Public Function htmlStart() As String
Return ""
End Function
Public Function htmlEnd() As String
Return ""
End Function
Public Function getParentHtmlId() As String
Return strParentID
End Function
Public Sub setParentHtmlId(s As String)
strParentID = s
End Sub
End Class
a child class
Code:
Imports Microsoft.VisualBasic
Public Class clsLabel
Inherits clsHtmlElement
Private strForId As String
Public Function getForId() As String
Return strForId
End Function
Public Sub setForId(s As String)
strForId = s
End Sub
Public Overloads Function htmlStart() As String
Dim sRes As New StringBuilder
sRes.Append("<label")
If (getTheID().Length > 0) Then sRes.Append(" id=" + Chr(34) + getTheID() + Chr(34))
If (getName().Length > 0) Then sRes.Append(" name=" + Chr(34) + getName() + Chr(34))
If (getTheID().Length > 0) Then sRes.Append(" for=" + Chr(34) + strForId + Chr(34))
sRes.AppendLine(">" + getText())
Return sRes.ToString()
End Function
Public Overloads Function htmlEnd() As String
Return "</label>"
End Function
End Class
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Nov 9th, 2017, 11:36 AM
#8
Re: VB.Net > ASP - What I thought should work, isn`t
Ah, you are Overloading not overriding, there is a big difference.
If you have methods in a base class that you want a derived class to be able to replace then the base class needs to mark them as overridable (similar to virtual in Java), the derived class then needs to mark it's implementation as overrides to get the polymorphic behaviour you want.
-
Nov 9th, 2017, 11:47 AM
#9
Re: VB.Net > ASP - What I thought should work, isn`t
You've actually used Overloads rather than Overrides, and they are different.
Overloads allows you to create multiple routines with the same name, but using different parameter lists (so they can be used as a more efficient version of Optional parameters). This would be useful if you wanted to have variations of the routine at the same level, but it isn't what you want here.
Overrides is to allow you to replace the inherited routine, which is what you want here.
So, clsHtmlElement should have these changes:
Code:
Public Overridable Function htmlStart() As String
Return ""
End Function
Public Overridable Function htmlEnd() As String
Return ""
End Function
...and clsLabel should have these changes:
Code:
Public Overrides Function htmlStart() As String
...
Public Overrides Function htmlEnd() As String
edit: I should have refreshed the page, oops!
-
Nov 10th, 2017, 01:43 PM
#10
Thread Starter
Don't Panic!
Re: VB.Net > ASP - What I thought should work, isn`t
Thanks.
That makes sense. I'll have a go tonight and post back when it breaks .. or if it works
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Nov 10th, 2017, 07:16 PM
#11
Thread Starter
Don't Panic!
Re: VB.Net > ASP - What I thought should work, isn`t
Hi
Thank you for the assist. I changed the overidable and overrides parts and once I`d updated all the classes, actually works
I`ll post up with more woes later on when I`ve got to the next problem
night all!
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Nov 13th, 2017, 07:35 AM
#12
Member
Re: VB.Net > ASP - What I thought should work, isn`t
Originally Posted by Ecniv
Hi
I`ll post up with more woes later on when I`ve got to the next problem
remember, if debugging is the science of taking the bugs out.
programming is the art of putting them in
second place is just the first loser...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|