---
title: "Division med noll?"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/7382-division-med-noll"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "casca"
published: "2000-12-10T18:04:00.000Z"
updated: "2000-12-10T18:15:00.000Z"
replies: 1
views: 213
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/7382-division-med-noll"
---

# Division med noll?

## #1 — casca, 2000-12-10T18:04Z

Håller på med ett script, ganska enkelt utan databaser, använder textfiler istället. I koden har jag använt en del matematiska operatorer, typ "/" för delat och använt Round()-funktionen för att avrunda talen. Men nu så när textfilerna med resultaten innehåller "0" så klarar inte servern av att avrunda, får följande felmeddelande:

> Körningsfel i Microsoft VBScript fel '800a000b' 
>
> Division med noll 
>
> /polly-v1/default.asp, rad 60

Och här är koden:

```
<%
    ' Declaring variables
    ' -------------------
    Dim Yes, No, Tot, yesShow, noShow, yesCheck, noCheck, Question
    Set C = Server.CreateObject("Scripting.FileSystemObject")

    ' Let's read some files
    ' ---------------------
    Set T = C.OpenTextFile(Server.MapPath("db\yes.txt"), 1)
    Yes = T.ReadAll
    T.Close

    Set T = C.OpenTextFile(Server.MapPath("db\question.txt"), 1)
    Question = T.ReadAll
    T.Close

    ' And the last file-read
    ' ----------------------
    Set T = C.OpenTextFile(Server.MapPath("db\no.txt"), 1)
    No = T.ReadAll
    T.Close

    ' Checking which alternative is chosen
    ' ------------------------------------
     If Request.Querystring("id") = "yes" Then
    Set T = C.OpenTextFile(Server.MapPath("db\yes.txt"), 2)
    Yes = CInt(Yes) + 1 
    T.WriteLine Yes

     ElseIf Request.Querystring("id") = "no" Then 
    Set T = C.OpenTextFile(Server.MapPath("db\no.txt"), 2)
    No = CInt(No) + 1
    T.WriteLine No
    T.Close

     End If

    ' And now som calculating
    ' -----------------------
    If Yes = "0" OR No = "0" Then
     yesShow = Yes
     noShow = No
    Else
     yesShow = Round(Yes / Tot * 100, 0)
     noShow = Round(No / Tot * 100, 0)
     Tot = CInt(Yes) + CInt(No)
    End If

    ' This isn't really necessary, but still useful
    ' ---------------------------------------------
    Set T = Nothing
    Set C = Nothing

    ' End of Script
    ' -------------
    %>
```

Har, som ni ser, testat med en If-sats för att kolla om textfilerna innehåller 0 röster, men det funkar ändå inte! :(

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

## #2 — Grummel, 2000-12-10T18:15Z

Du måste ju ta bort hartassarna kring nollan i if-satsen, annars kontrollerar satsen om Yes innehåller strängen "0".

```
If Yes = "0" OR No = "0" Then
```

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

---

Tråden på webben: https://www.webforum.nu/amne/asp/7382-division-med-noll
