Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Structures and Strings 3

Status
Not open for further replies.

Dimandja

Programmer
Apr 29, 2002
2,720
US
Code:
        Structure myRecord
            <VBFixedString(2)> Public v1 As String
            <VBFixedString(2)> Public v2 As String
            <VBFixedString(2)> Public v3 As String
        End Structure
A couple of questions.

1. Can those variables maintain and preserve their specified lengths?
2. How do you move a string ("aabbcc") into myRecord (and back), and have those variables correctly populated, without addressing them individually as in: myRecord.v1 = "aa"...?
 
Thanks, Rick.

But how would you move "aabbcc" into that Class, without raising a casting exception?
 
With a method, or as a parameter in the constructor.

Something like this:

Code:
Public Class myRecord
  private m_v1(2) as char
  private m_v2(2) as char
  private m_v3(2) as char

  Public Property V1() As Integer
    Get
      Return m_v1
    End Get
    Set(ByVal Value As Integer)
      m_v1 = Value
    End Set
  End Property

  'repeat property for m_v2 and m_v3

  public sub overloads New()
    v1="  "
    v2="  "
    v3="  "
  end sub

  public sub overloads New(InitialValues(6) as char)
    SetValues(InitialValues(6)
  end sub

  public sub overloads New(v1(2) as char, v2(2) as char, v3(2) as char)
    SetValues(v1,v2,v3)
  end sub

  public sub overloads SetValues(InitialValues(6) as char)
    v1=InitialValues(0) & InitialValues(1)
    v2=InitialValues(2) & InitialValues(3)
    v3=InitialValues(4) & InitialValues(5)
  end sub

  public sub overloads SetValues(v1(2) as char, v2(2) as char, v3(2) as char)
    me.v1=v1
    me.v2=v2
    me.v3=v3
  end sub
End Class

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I was able to convince management to convert to Class. We are now laboriously coding properties. And we decided to go with the SetValues model. Thanks.
 
We are now laboriously coding properties

I hear ya! One of our next projects at work is to create a class builder for our data layer. It should (when completed) create a series of stored procedures for a table, the data and business layer class code, and all field properties. Take class building from a 2 hour affair to a 2 minute button click.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Wow! I could use such an animal! In fact, when I looked at the amount of similar but tedious code to be produced, I thought about automating the process. I'm glad to see that that thought was not entirely off the wall; somebody else is doing it.
 
Y'all know that there's a bunch of code generators available? Almost all of them automate property creation.

Here's a list:

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Very cool chiph. now wich ones are the best. already tried likemania and it creates code faster then my shadow. If only I had that during the exams.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
I've used CodeSmith (not a free tool) to generate c# code, and it works nicely. They may have VB.NET templates available too, I don't know.

Also, with the CodeDOM that is built into the .net framework, you can write your own code generator. It's a little tricky to use, and isn't a complete implementation (no support for enumerations), but you can generate c# or VB.NET as you wish just by changing a couple of properties.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top