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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is the faster way to turn variant into integer?

Status
Not open for further replies.

greenbambootea

IS-IT--Management
Mar 23, 2007
11
US
What I am dealing with now is to read data from another program in Excel by using DDE. the VBA code is something like following:


channel = Application.DDEInitiate("cqgpc", "CLESK07") data_sheet.Cells(99 + row, 15) = Application.DDERequest(channel, "Y_Settlement")
temp(row, 3) = data_feed_justify(99 + row,15)
Application.DDETerminate (channel)

data_feed_justify is just a function to figure out the value which should be get for temp. Basically, the returns from DDErequest could be an empty string, a string with 8 blanks, #value!, or an integer. In this case, can somebody suggest a faster way to get the value instead of using a cell as a "bridge". Cint()does not work.
 
Can you post the code for data_feed_justify(), so we can see what your expected output should look like? You say Cint() doesn't work - what are you expecting to happen when you get something other than an integer returned?

Also, are you doing this connect-get-disconnect process in a loop? If so, change it to connect once, loop around getting the data, then disconnect.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
You could use
Code:
VarType(YourVariant)
and see what that returns. Check the help for a list of values for the different datatypes.

Cheers,

Roel
 
Thanks for the reply. The return type is variant. the code for data_feed_justify is:

Function data_feed_justify(row As Integer, col As Integer, flag As Integer) As Integer
Dim temp As Integer
If IsError(control_sheet.Cells(row, col)) Then
If flag = 1 Then
data_feed_justify = negative_number
Else
data_feed_justify = positive_number
End If
Else
temp = Len(control_sheet.Cells(row, col))
If temp = 8 Or temp = 0 Then
If flag = 1 Then
data_feed_justify = negative_number
Else
data_feed_justify = positive_number
End If
Else
data_feed_justify = control_sheet.Cells(row, col)
End If
End If
End Function


Basically, I used cell as a "bridge" to turn Variant into integer. It cost me quite a percent of time. So I was wondering if there are some other faster way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top