473,398 Members | 2,125 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,398 software developers and data experts.

need to convert variant to double... somehow

n8kindt
221 100+
i've got a brainteaser for you guys. let's say i have a form called "Form1"...
now, i have a lot of fields on Form1 and get tired of typing out forms!form1.fillintheblank.value because they are referenced quite a bit. so i want to create a function that will fill in the blank and return the value that resides in that location. the problem is, once it is converted to string (in order to use concatenation) i can't seem to convert it back to a true variant. it always retains the form of a string. take this for example:

Expand|Select|Wrap|Line Numbers
  1. Function Permissions(Root As String)
  2. Dim strRoot As String
  3. Dim varRoot As Variant
  4. strRoot = "[Forms]![Form1].[" & Root & "].value"
  5. varRoot = (CVar(strRoot)
  6. If CurrentProject.AllForms("Form1").IsLoaded Then
  7. Permissions = Nz(varRoot, 0)
  8. Else: Permissions = 0
  9. End If
  10. Debug.Print Permissions
  11. End Function
the output of Permissions("Hello") is:
[Forms]![Form1].[Hello].value

i would much rather have the output be whatever value is in that field :)
is there any possible way around this? i've thrown the kitchen sink at this problem and i've got nothing. any suggestions? thanks guys.
--nate
Jun 19 '08 #1
6 9812
ADezii
8,834 Expert 8TB
This is absolutely no need to always use the Fully Qualified Reference for a Form Field, use the Shortcut Version:
Expand|Select|Wrap|Line Numbers
  1. 'to refer to the [txtLastName] Field on Form1
  2. Dim frm As Form
  3.  
  4. Set frm = Forms![Form1]
  5. Debug.Print frm![txtLastName]
Jun 19 '08 #2
n8kindt
221 100+
This is absolutely no need to always use the Fully Qualified Reference for a Form Field, use the Shortcut Version:
Expand|Select|Wrap|Line Numbers
  1. 'to refer to the [txtLastName] Field on Form1
  2. Dim frm As Form
  3.  
  4. Set frm = Forms![Form1]
  5. Debug.Print frm![txtLastName]
i'm not sure what that does for me. i added this to my code it still returned the value as a string--not the value in the form:

Expand|Select|Wrap|Line Numbers
  1. Function Permissions(Root As Variant)
  2. Dim strRoot As String
  3. Dim varRoot As Variant
  4. Dim CvarRoot As Variant
  5. Dim frm As Form
  6.  
  7. 'to refer to frm!Root as defined in function
  8. Set frm = Forms![Form1]
  9. strRoot = "frm!" & Root
  10. CvarRoot = CVar(strRoot)
  11. varRoot = CvarRoot
  12.  
  13. If CurrentProject.AllForms("Form1").IsLoaded Then
  14. Permissions1 = Nz(varRoot, 0)
  15. Else: Permissions = 0
  16. End If
  17. Debug.Print Permissions
  18. End Function
somehow i need to concatenate 2 variants--WITHOUT converting it to a string. and i have no idea if this is possible or how it would be done.
Jun 19 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi Nate. I think there is some confusion over what you are trying to achieve; if you want to return the value of a control you don't need the various variable assignments in your function, and as ADezii has pointed out you can refer to a field directly.

There are several ways to do so. I use the following general function, supplying as arguments the name of the form and the name of the field whose value is to be returned as strings in each case:

Expand|Select|Wrap|Line Numbers
  1. Public Function FormFieldValue(FormName As String, FieldName As String)
  2.     FormFieldValue = Forms(FormName).Controls(FieldName)
  3. End Function
The function is untyped (it returns a variant value).

I use this function in complex Access queries to replace direct form field references, which the Jet Database Engine often cannot recognise.

-Stewart
Jun 20 '08 #4
NeoPa
32,556 Expert Mod 16PB
For controls within the current form, called from within the form's module, you need even less.
For clarity, most use Me. in front of control references, but that, and the .Value, are actually defaulted anyway, so a reference to Me.ControlName.Value, can actually be expressed in the code simply as ControlName.
Expand|Select|Wrap|Line Numbers
  1. X = ControlName
Jun 20 '08 #5
n8kindt
221 100+
For controls within the current form, called from within the form's module, you need even less.
For clarity, most use Me. in front of control references, but that, and the .Value, are actually defaulted anyway, so a reference to Me.ControlName.Value, can actually be expressed in the code simply as ControlName.
Expand|Select|Wrap|Line Numbers
  1. X = ControlName
alright, i didn't know that. that is good to know. thanks, NeoPa
Jun 20 '08 #6
n8kindt
221 100+
Hi Nate. I think there is some confusion over what you are trying to achieve; if you want to return the value of a control you don't need the various variable assignments in your function, and as ADezii has pointed out you can refer to a field directly.

There are several ways to do so. I use the following general function, supplying as arguments the name of the form and the name of the field whose value is to be returned as strings in each case:

Expand|Select|Wrap|Line Numbers
  1. Public Function FormFieldValue(FormName As String, FieldName As String)
  2.     FormFieldValue = Forms(FormName).Controls(FieldName)
  3. End Function
The function is untyped (it returns a variant value).

I use this function in complex Access queries to replace direct form field references, which the Jet Database Engine often cannot recognise.

-Stewart
PERFECT! yes, that is exactly what i was trying to achieve. sorry for explaining it so poorly. i will try this out but i'm sure it will work. thank you so much!
Jun 20 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: DanSteph | last post by:
hello all, I have a problem, I have a DOUBLE value like that 4065 4000 0000 0000 and I want to convert it to a DWORD like that: 4065 4000 if I do result=(DWORD)MyDouble it end with...
3
by: Norvin Laudon | last post by:
Hi, Can somebody explain the following, from the MSDN documentation for the "System.Convert.ToInt32(double)" function <quote> Return Value value rounded to the nearest 32-bit signed...
17
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge...
3
by: PeterK | last post by:
I am trying to set Public overridable CreditlimitS() as System.Data.SqlTypes.SqlMoney to Creditlimit as Double like CreditLimitS=creditlimit and get this error "Value of type double cannot be...
6
by: Doug | last post by:
Hi I have a short piece of trial code that compares some input and then produces a message based on the value. However I get a build error that i dont know how to resolve ' Cannot implicitly...
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However...
1
by: michael mazanek | last post by:
Hi all, i have a VARIANT variable which contains a "friendly name" of a video-codec (direct show). Does anyone know how to retrieve the friendly name as a string to display it on the console? ...
2
by: ElizaInternet | last post by:
I need convert NITF Xmls for insert into BD SQL. I try convert to file text and then insert into BD I used the Syndication:NITF of perl for this convertion. Any have information about this??, I...
1
by: rhyme2ri2 | last post by:
Hello all, how can i convert a variant data type into image. Actually i am retrieving an image from CCD (camera) which is in variant format. Now i want to display this image in picture/image...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.