473,811 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Type mismatch in function

218 Recognized Expert New Member
Hi

Any idea why the following (cut down) function gives a "Type Mismatch" error?
I've tried almost everything, in terms of arrays, etc, but I need to pass back 3 values (int, int, double)
"GradeData" is simply a user-defined type containing 2 integers and a double..
Expand|Select|Wrap|Line Numbers
  1. Public Function GroupGradeCount(GroupIdent As Integer, GradeIdent As Integer, ColNum As Integer) As GradeData
  2.     Dim Res1 As Integer
  3.     Dim Res2 As Integer
  4.     Dim Res3 As Double
  5.     Dim retVar As GradeData
  6.     Res1 = 19
  7.     Res2 = 21
  8.     Res3 = 100 * (Res1 / Res2)
  9.     retVar.Count = Res1
  10.     retVar.Total = Res2
  11.     retVar.Percent = Res3
  12.     GroupGradeCount = retVar
  13. End Function
All suggestions gratefully received.

TIA

Steve
Jan 12 '07 #1
3 2604
NeoPa
32,579 Recognized Expert Moderator MVP
Don't you need to use Set for the last line :
Expand|Select|Wrap|Line Numbers
  1. Set GroupGradeCount = retVar
Jan 12 '07 #2
MMcCarthy
14,534 Recognized Expert Moderator MVP
Hi

Any idea why the following (cut down) function gives a "Type Mismatch" error?
I've tried almost everything, in terms of arrays, etc, but I need to pass back 3 values (int, int, double)
"GradeData" is simply a user-defined type containing 2 integers and a double..
Expand|Select|Wrap|Line Numbers
  1. Public Function GroupGradeCount(GroupIdent As Integer, GradeIdent As Integer, ColNum As Integer) As GradeData
  2.     Dim Res1 As Integer
  3.     Dim Res2 As Integer
  4.     Dim Res3 As Double
  5.     Dim retVar As GradeData
  6.     Res1 = 19
  7.     Res2 = 21
  8.     Res3 = 100 * (Res1 / Res2)
  9.     retVar.Count = Res1
  10.     retVar.Total = Res2
  11.     retVar.Percent = Res3
  12.     GroupGradeCount = retVar
  13. End Function
All suggestions gratefully received.

TIA

Steve
Which line exactly is the code breaking on?
Jan 12 '07 #3
ADezii
8,834 Recognized Expert Expert
Hi

Any idea why the following (cut down) function gives a "Type Mismatch" error?
I've tried almost everything, in terms of arrays, etc, but I need to pass back 3 values (int, int, double)
"GradeData" is simply a user-defined type containing 2 integers and a double..
Expand|Select|Wrap|Line Numbers
  1. Public Function GroupGradeCount(GroupIdent As Integer, GradeIdent As Integer, ColNum As Integer) As GradeData
  2.     Dim Res1 As Integer
  3.     Dim Res2 As Integer
  4.     Dim Res3 As Double
  5.     Dim retVar As GradeData
  6.     Res1 = 19
  7.     Res2 = 21
  8.     Res3 = 100 * (Res1 / Res2)
  9.     retVar.Count = Res1
  10.     retVar.Total = Res2
  11.     retVar.Percent = Res3
  12.     GroupGradeCount = retVar
  13. End Function
All suggestions gratefully received.

TIA

Steve
If you pass a String Variable to either of the Arguments of the GroupGradeCount Function, you will receive a Type Mismatch Error. Could this be the case? When passed 3 Integers, 2 Integers and a Double will successfully be returned by the Function via the User Defined Type. The code works fine in the below context:
Expand|Select|Wrap|Line Numbers
  1. Public Type GradeData
  2.   Count As Integer
  3.   Total As Integer
  4.   Percent As Double
  5. End Type
Expand|Select|Wrap|Line Numbers
  1. Dim M As GradeData
  2. M = GroupGradeCount(341, 2898, 454)
  3. MsgBox M.Count      'Integer
  4. MsgBox M.Total      'Integer
  5. MsgBox M.Percent    'Double
Jan 13 '07 #4

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

Similar topics

4
10699
by: Laura | last post by:
Help. Below is my code. Getting Type mismatch error on the noted line. I'm trying to send an array (aryNewD) with 4 columns and x rows to a function to save all the array info into a SQL Server table via a stored procedure. Keep getting this error. Any suggestions? Code: 'ASP: if blnNewD then
1
5708
by: Gordon | last post by:
I'm just getting started in ASP and can't seem to figure out how to run a function in ASP. I get an error of "Line 11 - Type Mismatch:'myvalidate'. Line 11 is the Input Button. Here is my simple page's code, what's wrong???: <%@LANGUAGE="VBSCRIPT"%> <% sub myvalidate() response.write("ok")
1
2296
by: Mark | last post by:
Hi - I tried this in VS.Net, and also in the Web Matrix code below: - but I am getting a type mismatch error. The sql statement runs perfectly from within the Access Query Designer. Can anyone verify the syntax, and that my .net code is ok - the type mismatch is happening at: DataGrid1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection) Thanks in advance,
3
2918
by: amitbadgi | last post by:
I am getting teh following error while converting an asp application to asp.net, Exception Details: System.Runtime.InteropServices.COMException: Type mismatch. Source Error: Line 347: 'response.Write(sql2)
3
2160
by: jg | last post by:
in VB 2005 the class myClass, I have Dim someStringArrary() As String --- sub New() MyBase.New() ... 'values assigned to elements of someStringArrary End Sub ......
2
1942
by: Rehan | last post by:
Hi there! Please help me out here. I am an inch away from completing my assignment. I am very new to VBA but i have very less time to be efficient at it. I am getting a type mismatch error when i click the button whose code is:
5
1818
by: daniel.hedz | last post by:
I am generating a usercontrol dynamically successfully, but when I try to find that usercontrol I get a type mismatch. This is what I am doing: //Loading my usercontrol MyWebApp.Folder.Folder.MyUsercontrol myUC = (MyWebApp.Folder.Folder.MyUsercontrol) LoadControl("~/Folder/Folder/MyUsercontrol.ascx");
5
4413
by: Davros9 | last post by:
Trying to get Regular Expressions working....... ---------------- Public Function SepString(InField As String) As String ''seperates on space and comma Dim RE As New RegExp Dim Matches As Match RE.IgnoreCase = True
2
9009
by: psychomad | last post by:
Please, can someone help me out to solve this error, i've been searching throughout my codes and yet i didnt succeed in finding the error!!!! The Error is: Server Error in '/' Application. -------------------------------------------------------------------------------- Data type mismatch in criteria expression.
19
21578
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the date is more than 10 months out. The query runs fine, but I when I put the criteria of >10 I get 'Data Type mismatch' error. The code below is the original query. I have since put all the datediff bit in code, with all variables declared as date,...
0
9728
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
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10648
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
10389
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...
0
10135
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...
1
7670
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...
0
6890
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.