473,804 Members | 3,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need to convert variant to double... somehow

n8kindt
221 New Member
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("He llo") 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 9863
ADezii
8,834 Recognized Expert Expert
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 New Member
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 Recognized Expert Moderator Specialist
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,579 Recognized Expert Moderator MVP
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 New Member
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 New Member
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
2324
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 AA(170)
3
6745
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 integer. If value is halfway between two whole numbers, the even number is returned; that is, 4.5 is
17
4383
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 problem writing VB Double values to the file so as the Pascal program can read them as Pascal Real values. I've managed to find the algorithm to read the Pascal Real format and convert it to a VB Double, but I cannot figure out the opposite...
3
7716
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 converted to System.Data.SqlTypes.SqlMoney " How do I get creditlimit into creditlimitS? There seems to be no conversion function. TIA
6
17004
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 convert type 'double' to 'bool' The code is
4
4526
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 it seems this convert is determined by the local settings and comma is indeed used as decimal separator. Is there another way to convert a dotted value to a double variable? Like 1234.5 and not 1234,5
1
5825
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? Thanks for any advice! mm
2
2411
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 can´t convert all tags and export to file text. Somebody knows another form to do it??? thanks for help
1
1839
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 box.(that is what i thought cud b one way ; feel free to suggest some other way of displaying my image). How can i convert this variant type to image. Any help wud b appreciated Thanks & Regards
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10571
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10326
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9143
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.