0

I defined few variables with these lines:

Dim RAM, VRAM, Storage, Budget As Integer

Dim CPU, GPU As String

Now I try to call a function which is defined like this:

Sub PCBuilder(CPU As String, GPU As String, RAM As Integer, Storage As Integer, VRAM As Integer, Budget As Integer)

When I try to run the code i get an error "ByRef argument type mismatch"

I noticed that only GPU and Budget have the right type, the other variables are defined as Variant.

Why is this happening and how can i fix it?

Roy Shiff
  • 63
  • 7
  • 3
    When delimiting your dims with a comma like that, only the last one will be properly dimmed as how it is stated. The rest will be `Variant` by default. The proper syntax for your dims is: `Dim RAM as integer, VRAM as integer, etc...` – Plutian Jan 31 '20 at 12:58
  • it worked, thanks i thought i could declare that way as it did not show any error until i added the function. is there a specific reason to use long? the numbers are always integers and they never go above 20. – Roy Shiff Jan 31 '20 at 13:02
  • https://stackoverflow.com/questions/26409117/why-use-integer-instead-of-long This does a good job of explaining it. – Warcupine Jan 31 '20 at 13:04
  • Reason for using Long is that Integer has no benefit in VBA (ether men usage, nor exec time), just the overflow downside,, so get used to not using (besides API arguments that must be Integer!). Have a look at [RubberduckVBA](http://rubberduckvba.com/) addin to get usefull hints on code – ComputerVersteher Jan 31 '20 at 13:07
  • ok good to know there is no real reason to use integer, i will start using long instead, thanks for the quick help – Roy Shiff Jan 31 '20 at 13:12

0 Answers0