---
title: "Inkompatibla typer: 'ch'"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/55141-inkompatibla-typer-ch"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Addeladde"
published: "2002-10-04T20:25:09.000Z"
updated: "2002-10-04T22:35:20.000Z"
replies: 10
views: 253
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/55141-inkompatibla-typer-ch"
---

# Inkompatibla typer: 'ch'

## #1 — Addeladde, 2002-10-04T20:25Z

Får felmeddelandet:

Inkompatibla typer: 'ch'

```
Function HexToDec(cadhex)
       Dim n, i, ch, decimal
       decimal = 0
	   n = Len(cadhex)
       For i=1 To n
       ch = Mid(cadhex, i, 1)
       If isHex(ch) Then
       decimal = decimal * 16
       If isDigit(c) Then
       decimal = decimal + ch
       Else
       decimal = decimal + Asc(uCase(ch)) - Asc("A")
       End If
       Else
       HexToDec = -1
       End If
       Next
       HexToDec = decimal
End Function
```

Permalänk: https://www.webforum.nu/p/55141

## #2 — LarsG, 2002-10-04T20:39Z

Jag vet inte varför det blir fel, men det räcker med detta för att konvertera från hex till decimalt.

```
decimalNumber = clng("&H" & hexValue)
```

Permalänk: https://www.webforum.nu/p/810907

## #3 — Addeladde, 2002-10-04T20:43Z

Den här kodbiten är en del av det som jag postade i den tidigare tråden om kodexempel

Permalänk: https://www.webforum.nu/p/810910

## #4 — solbulle, 2002-10-04T22:03Z

Om jag byter ut den funktionen till LarsGs förslag så lirar det för mig i alla fall, vad jag kan se.

```
Function HexToDec(cadhex)
    
       HexToDec =  clng("&H" & cadhex)

End Function
```

Permalänk: https://www.webforum.nu/p/810969

## #5 — Addeladde, 2002-10-04T22:15Z

Jag får inte dimensionerna att stämma?

Permalänk: https://www.webforum.nu/p/810975

## #6 — solbulle, 2002-10-04T22:20Z

Stämmer för mig på gif o jpg i alla fall... Hur blir det för dig?

Permalänk: https://www.webforum.nu/p/810978

## #7 — Addeladde, 2002-10-04T22:22Z

på jpg och gif får jag konstiga resultat.

Kan du inte posta hela ditt kodexempel som du har fått att fungera. Jag antar att du fått gjort andra ändringar?

Permalänk: https://www.webforum.nu/p/810979

## #8 — solbulle, 2002-10-04T22:24Z

Inga egentliga ändringar: (Nja, en fil)

```
<%
Dim HW

Function AscAt(s, n)
       AscAt = Asc(Mid(s, n, 1))
End Function

Function HexAt(s, n)
       HexAt = Hex(AscAt(s, n))
End Function

Function isJPG(fichero)
       If inStr(uCase(fichero), ".JPG") <> 0 Then
       isJPG = true
       Else
       isJPG = false
       End If
End Function

Function isPNG(fichero)
       If inStr(uCase(fichero), ".PNG") <> 0 Then
       isPNG = true
       Else
       isPNG = false
       End If
End Function

Function isGIF(fichero)
       If inStr(uCase(fichero), ".GIF") <> 0 Then
       isGIF = true
       Else
       isGIF = false
       End If
End Function

Function isBMP(fichero)
       If inStr(uCase(fichero), ".BMP") <> 0 Then
       isBMP = true
       Else
       isBMP = false
       End If
End Function

Function isWMF(fichero)
       If inStr(uCase(fichero), ".WMF") <> 0 Then
       isWMF = true
       Else
       isWMF = false
       End If
End Function

Function isWebImg(f)
       If isGIF(f) Or isJPG(f) Or isPNG(f) Or isBMP(f) Or isWMF(f) Then
       isWebImg = true
       Else
       isWebImg = true
       End If
End Function

Function ReadImg(fichero)
       If isGIF(fichero) Then
       ReadImg = ReadGIF(fichero)
       Else
       If isJPG(fichero) Then
       ReadImg = ReadJPG(fichero)
       Else
       If isPNG(fichero) Then
       ReadImg = ReadPNG(fichero)
       Else
       If isBMP(fichero) Then
       ReadImg = ReadPNG(fichero)
       Else
       If isWMF(fichero) Then
       ReadImg = ReadWMF(fichero)
       Else
       ReadImg = Array(0,0)
       End If
       End If
       End If
       End If
       End If
End Function

Function ReadJPG(fichero)
    Dim fso, ts, s, HW, nbytes
       HW = Array("","")
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1)
       s = Right(ts.Read(167), 4)
       HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4))
       HW(1) = HexToDec(HexAt(s,1) & HexAt(s,2))
       ts.Close
    ReadJPG = HW
End Function

Function ReadPNG(fichero)
    Dim fso, ts, s, HW, nbytes
       HW = Array("","")
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1)
       s = Right(ts.Read(24), 8)
       HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4))
       HW(1) = HexToDec(HexAt(s,7) & HexAt(s,8))
       ts.Close
    ReadPNG = HW
End Function

Function ReadGIF(fichero)
    Dim fso, ts, s, HW, nbytes
       HW = Array("","")
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1)
       s = Right(ts.Read(10), 4)
       HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1))
       HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3))
       ts.Close
    ReadGIF = HW
End Function

Function ReadWMF(fichero)
    Dim fso, ts, s, HW, nbytes
       HW = Array("","")
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1)
       s = Right(ts.Read(14), 4)
       HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1))
       HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3))
       ts.Close
    ReadWMF = HW
End Function

Function ReadBMP(fichero)
    Dim fso, ts, s, HW, nbytes
       HW = Array("","")
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1)
       s = Right(ts.Read(24), 8)
       HW(0) = HexToDec(HexAt(s,4) & HexAt(s,3))
       HW(1) = HexToDec(HexAt(s,8) & HexAt(s,7))
       ts.Close
    ReadBMP = HW
End Function

Function isDigit(c)
       If inStr("0123456789", c) <> 0 Then
       isDigit = true
       Else
       isDigit = false
       End If
End Function

Function isHex(c)
       If inStr("0123456789ABCDEFabcdef", c) <> 0 Then
       isHex = true
       Else
       ishex = false
       End If
End Function

Function HexToDec(cadhex)

HexToDec = clng("&H" & cadhex)

End Function
%>

<html><head>
<TITLE>dbtable.asp</TITLE>
</head>
<body bgcolor="#FFFFFF">
<%
   graphic="images/learnaspiconmain.gif"
   HW = ReadImg(graphic)
   Response.Write graphic & " Dimensions: " & HW(0) & "x" & HW(1) & "<br>"
   response.write "<img src=""/" & graphic & """" 
   response.write height=""" & HW(0) & """
   response.write width=""" & HW(0) & "">"
%>
</body></html>
```

Permalänk: https://www.webforum.nu/p/810981

## #9 — Addeladde, 2002-10-04T22:27Z

Fungerar med alla bilder som jag testat utom den här: <http://member.webforum.nu/1358/2.jpg>

Permalänk: https://www.webforum.nu/p/810984

## #10 — solbulle, 2002-10-04T22:30Z

Hm... nej du, den fungerar inte för mig heller :( Får: images/2.jpg Dimensions: 317x3601

Permalänk: https://www.webforum.nu/p/810986

## #11 — Addeladde, 2002-10-04T22:35Z

Samma för mig. Undra varför?

Permalänk: https://www.webforum.nu/p/810989

---

Tråden på webben: https://www.webforum.nu/amne/asp/55141-inkompatibla-typer-ch
