473,322 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Setting MaxLength to <VBFixedString(x)>?

I declare the following variable in one of my structures...

<VBFixedString(17)> Dim Name As String

Fixed to 17 because it's written to a random-access file.

Is there any way to tie the MaxLength of a TextBox to this value?

Thanks,
The Confessor
Jan 12 '06 #1
9 6535
"The Confessor" <in*****@reply.to.group> schrieb:
<VBFixedString(17)> Dim Name As String

Fixed to 17 because it's written to a random-access file.

Is there any way to tie the MaxLength of a TextBox to this value?


\\\
<VBFixedString(17)> Private X As String
..
..
..
Dim fi As FieldInfo = _
Me.GetType().GetField( _
"X", _
BindingFlags.Instance Or BindingFlags.NonPublic _
)
MsgBox( _
DirectCast( _
fi.GetCustomAttributes( _
GetType(VBFixedStringAttribute), _
False _
)(0), _
VBFixedStringAttribute _
).Length _
)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jan 12 '06 #2
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in
news:ui**************@TK2MSFTNGP09.phx.gbl:
"The Confessor" <in*****@reply.to.group> schrieb:
<VBFixedString(17)> Dim Name As String

Fixed to 17 because it's written to a random-access file.

Is there any way to tie the MaxLength of a TextBox to this value?


\\\
<VBFixedString(17)> Private X As String
.
.
.
Dim fi As FieldInfo = _
Me.GetType().GetField( _
"X", _
BindingFlags.Instance Or BindingFlags.NonPublic _
)
MsgBox( _
DirectCast( _
fi.GetCustomAttributes( _
GetType(VBFixedStringAttribute), _
False _
)(0), _
VBFixedStringAttribute _
).Length _
)
///


Thank you very much for your reply, Herfried.
Jan 13 '06 #3
I'm completely confused. What exactly are we trying to accomplish here?
Normally I can figure stuff out, but I'm drawing a blank on this one.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ui**************@TK2MSFTNGP09.phx.gbl...
"The Confessor" <in*****@reply.to.group> schrieb:
<VBFixedString(17)> Dim Name As String

Fixed to 17 because it's written to a random-access file.

Is there any way to tie the MaxLength of a TextBox to this value?


\\\
<VBFixedString(17)> Private X As String
.
.
.
Dim fi As FieldInfo = _
Me.GetType().GetField( _
"X", _
BindingFlags.Instance Or BindingFlags.NonPublic _
)
MsgBox( _
DirectCast( _
fi.GetCustomAttributes( _
GetType(VBFixedStringAttribute), _
False _
)(0), _
VBFixedStringAttribute _
).Length _
)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 13 '06 #4
"Terry Olsen" <to******@hotmail.com> wrote in news:ePP#Ei#FGHA.1028
@TK2MSFTNGP11.phx.gbl:
I'm completely confused. What exactly are we trying to accomplish here?
Normally I can figure stuff out, but I'm drawing a blank on this one.


Strings used in Random Access files require a <VBFixedString()> modifier
because each record in a RAF must be of equivalent length.

If your user inputs that data in a TextBox, there's a chance he'll proceed
beyond that allotted length, in which case the data will be trunecated...
so it's helpful to set the TextBox's MaxLength = to the number of
characters the string is restricted to...

Unfortunately, this results in repetition of effort: a change must be
reflected in *both* places... which can lead to discrepencies.

It's much easier to find a way to set TextBox's MaxLength = to the
fixedstring length, and only worry about modifying *one* line of code to
make such a change.
Jan 13 '06 #5
Ok, I get it. But if the string is always 17 and the TextBox.Length is
always 17, it seems like 2 lines of code would be easier than the
multi-lined code earlier in this thread:

<VBFixedString(17)> Dim X as String
TextBox1.MaxLength=17
"The Confessor" <in*****@reply.to.group> wrote in message
news:Xn*********************************@130.81.64 .196...
"Terry Olsen" <to******@hotmail.com> wrote in news:ePP#Ei#FGHA.1028
@TK2MSFTNGP11.phx.gbl:
I'm completely confused. What exactly are we trying to accomplish here?
Normally I can figure stuff out, but I'm drawing a blank on this one.


Strings used in Random Access files require a <VBFixedString()> modifier
because each record in a RAF must be of equivalent length.

If your user inputs that data in a TextBox, there's a chance he'll proceed
beyond that allotted length, in which case the data will be trunecated...
so it's helpful to set the TextBox's MaxLength = to the number of
characters the string is restricted to...

Unfortunately, this results in repetition of effort: a change must be
reflected in *both* places... which can lead to discrepencies.

It's much easier to find a way to set TextBox's MaxLength = to the
fixedstring length, and only worry about modifying *one* line of code to
make such a change.

Jan 13 '06 #6

Terry Olsen wrote:
Ok, I get it. But if the string is always 17 and the TextBox.Length is
always 17, it seems like 2 lines of code would be easier than the
multi-lined code earlier in this thread:

<VBFixedString(17)> Dim X as String
TextBox1.MaxLength=17


Or...

Public Const STRING_LENGTH As Integer = 17

<VBFixedString (STRING_LENGTH)> Dim X As String
TextBox1.MaxLength = STRING_LENGTH

Now, you only have to change the constant...

--
Tom Shelton

Jan 13 '06 #7
Touche' :-)

"Tom Shelton" <to*@mtogden.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...

Terry Olsen wrote:
Ok, I get it. But if the string is always 17 and the TextBox.Length is
always 17, it seems like 2 lines of code would be easier than the
multi-lined code earlier in this thread:

<VBFixedString(17)> Dim X as String
TextBox1.MaxLength=17


Or...

Public Const STRING_LENGTH As Integer = 17

<VBFixedString (STRING_LENGTH)> Dim X As String
TextBox1.MaxLength = STRING_LENGTH

Now, you only have to change the constant...

--
Tom Shelton

Jan 13 '06 #8
The Confessor wrote:
I declare the following variable in one of my structures...

<VBFixedString(17)> Dim Name As String

Fixed to 17 because it's written to a random-access file.


Might there be a platform issue using that? Could it be a Unicode string on
NT platforms but ANSI on W98?[1] And how does the requirement for a fixed
number of bytes in a file fight with the potentially variable number of
bytes of a UTF-8-encoded string?

[1]
http://msdn.microsoft.com/library/de...ui06042002.asp
Just after the third grey code block: "The VBFixedString attribute tells the
runtime that we will be using a fixed-length string that is 128 characters
long. The MarshalAs attribute lets the runtime know how to handle this
string at run time. What we are telling the compiler is that this string
will be 128 characters long (SizeConst:=128) and that the string should be
treated as a character set based on the platform (ByValTStr)."

Andrew
Jan 13 '06 #9
"Tom Shelton" <to*@mtogden.com> wrote in news:1137129284.491808.154410
@g47g2000cwa.googlegroups.com:

Terry Olsen wrote:
Ok, I get it. But if the string is always 17 and the TextBox.Length is
always 17, it seems like 2 lines of code would be easier than the
multi-lined code earlier in this thread:

<VBFixedString(17)> Dim X as String
TextBox1.MaxLength=17


Or...

Public Const STRING_LENGTH As Integer = 17

<VBFixedString (STRING_LENGTH)> Dim X As String
TextBox1.MaxLength = STRING_LENGTH

Now, you only have to change the constant...

--
Tom Shelton


Which does what I want far more simply than the previous code!

Thank you!
Jan 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Buck Turgidson | last post by:
According to an O'Reilly PHP book I have, setting variables_order to "ES" is safer, but that one will need to create global variables, not rely on them being created. Fair enough. But why does...
9
by: Lovely Dola | last post by:
I have set the MaxLength property of a textbox in a form to 5 at design time. When I change the MaxLength back to 0 during run-time under some condition (for example, after clicking a command...
2
by: sql | last post by:
Hi all, I would like to set MaxLength property of asp.net controls on my page based on their corresponding field length in Sql Server table. I know I can get the TableSchema along with the record...
2
by: dsnyder | last post by:
This HTML has a bit of Javascript at the end that puts the initial focus on the userID field. It works great on Windows2000 running IE6, but the initial focus never goes to the userID field on...
7
by: ray | last post by:
My xsd has the following element: <xs:element name="Company" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="1" /> <xs:maxLength value="5" />...
2
by: Craig G | last post by:
how do you do it? i understand the maxlength property has no effect but is there a way around it?
1
by: Anthony | last post by:
I am defining the datagridtable style for a grid .... Dim coursekeycol As New DataGridTextBoxColumn coursekeycol.MappingName = COURSEKEYCOLNAME coursekeycol.HeaderText = "" coursekeycol.Width...
5
by: jose1lm | last post by:
What is supposed to happen: A user enters data into one of the FORM input selections. When the user submits the form, the onclick event is supposed to go to a function that will set another FORM...
1
by: Mel | last post by:
Anyone know how I would retrieve the MaxLength property of a column in my Access Database table? I know how to retrieve table data, for example the "Quote #" field in my example code below, but I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.