---
# System prepended metadata

title: UFT GUItest - read txt content
tags: [GUItest, UFT]

---

---
title: 'UFT GUItest - read txt content'
disqus: hackmd
---

## UFT GUItest - Read txt content

* 讀取txt文字檔內容
* Micro Focus UFT One 15.0


## :rocket:參考程式
* 方法一：一行一行讀取
```vba=
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set txt = fso.OpenTextFile("C:\Test123.txt")
Do While txt.AtEndOfLine <> True
	retstring = txt.ReadLine
	msgbox retstring
Loop
txt.Close
```

* 方法二：可讀取文字
```vba=
Set objStream = CreateObject("ADODB.Stream")

objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile("C:\Users\Miranda\Documents\Test123.txt")

strData = objStream.ReadText()
msgbox strData

objStream.Close
Set objStream = Nothing
```


## Appendix and FAQ

:::info
**Find this document incomplete?** Leave a comment!
:::

###### tags: `UFT`,`GUItest`